Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtest: rename BenchHarness to Bencher #13236

Merged
merged 1 commit into from
Apr 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/doc/guide-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ runner.

The type signature of a benchmark function differs from a unit test:
it takes a mutable reference to type
`test::BenchHarness`. Inside the benchmark function, any
`test::Bencher`. Inside the benchmark function, any
time-variable or "setup" code should execute first, followed by a call
to `iter` on the benchmark harness, passing a closure that contains
the portion of the benchmark you wish to actually measure the
Expand All @@ -189,16 +189,16 @@ For example:
extern crate test;

use std::slice;
use test::BenchHarness;
use test::Bencher;

#[bench]
fn bench_sum_1024_ints(b: &mut BenchHarness) {
fn bench_sum_1024_ints(b: &mut Bencher) {
let v = slice::from_fn(1024, |n| n);
b.iter(|| {v.iter().fold(0, |old, new| old + *new);} );
}

#[bench]
fn initialise_a_vector(b: &mut BenchHarness) {
fn initialise_a_vector(b: &mut Bencher) {
b.iter(|| {slice::from_elem(1024, 0u64);} );
b.bytes = 1024 * 8;
}
Expand Down Expand Up @@ -249,11 +249,11 @@ it entirely.
~~~
# #[allow(unused_imports)];
extern crate test;
use test::BenchHarness;
use test::Bencher;

#[bench]
fn bench_xor_1000_ints(bh: &mut BenchHarness) {
bh.iter(|| {
fn bench_xor_1000_ints(b: &mut Bencher) {
b.iter(|| {
range(0, 1000).fold(0, |old, new| old ^ new);
});
}
Expand Down
28 changes: 13 additions & 15 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ impl<T> Drop for TypedArena<T> {
#[cfg(test)]
mod tests {
extern crate test;


use self::test::BenchHarness;
use self::test::Bencher;
use super::{Arena, TypedArena};

struct Point {
Expand All @@ -505,9 +503,9 @@ mod tests {
}

#[bench]
pub fn bench_copy(bh: &mut BenchHarness) {
pub fn bench_copy(b: &mut Bencher) {
let arena = TypedArena::new();
bh.iter(|| {
b.iter(|| {
arena.alloc(Point {
x: 1,
y: 2,
Expand All @@ -517,8 +515,8 @@ mod tests {
}

#[bench]
pub fn bench_copy_nonarena(bh: &mut BenchHarness) {
bh.iter(|| {
pub fn bench_copy_nonarena(b: &mut Bencher) {
b.iter(|| {
~Point {
x: 1,
y: 2,
Expand All @@ -528,9 +526,9 @@ mod tests {
}

#[bench]
pub fn bench_copy_old_arena(bh: &mut BenchHarness) {
pub fn bench_copy_old_arena(b: &mut Bencher) {
let arena = Arena::new();
bh.iter(|| {
b.iter(|| {
arena.alloc(|| {
Point {
x: 1,
Expand Down Expand Up @@ -558,9 +556,9 @@ mod tests {
}

#[bench]
pub fn bench_noncopy(bh: &mut BenchHarness) {
pub fn bench_noncopy(b: &mut Bencher) {
let arena = TypedArena::new();
bh.iter(|| {
b.iter(|| {
arena.alloc(Noncopy {
string: ~"hello world",
array: vec!( 1, 2, 3, 4, 5 ),
Expand All @@ -569,8 +567,8 @@ mod tests {
}

#[bench]
pub fn bench_noncopy_nonarena(bh: &mut BenchHarness) {
bh.iter(|| {
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
b.iter(|| {
~Noncopy {
string: ~"hello world",
array: vec!( 1, 2, 3, 4, 5 ),
Expand All @@ -579,9 +577,9 @@ mod tests {
}

#[bench]
pub fn bench_noncopy_old_arena(bh: &mut BenchHarness) {
pub fn bench_noncopy_old_arena(b: &mut Bencher) {
let arena = Arena::new();
bh.iter(|| {
b.iter(|| {
arena.alloc(|| Noncopy {
string: ~"hello world",
array: vec!( 1, 2, 3, 4, 5 ),
Expand Down
26 changes: 13 additions & 13 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ impl<'a> Iterator<uint> for BitPositions<'a> {
#[cfg(test)]
mod tests {
extern crate test;
use self::test::BenchHarness;
use self::test::Bencher;

use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn,
from_bytes};
Expand Down Expand Up @@ -1557,7 +1557,7 @@ mod tests {
}

#[bench]
fn bench_uint_small(b: &mut BenchHarness) {
fn bench_uint_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = 0 as uint;
b.iter(|| {
Expand All @@ -1567,7 +1567,7 @@ mod tests {
}

#[bench]
fn bench_small_bitv_small(b: &mut BenchHarness) {
fn bench_small_bitv_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = SmallBitv::new(uint::BITS);
b.iter(|| {
Expand All @@ -1577,7 +1577,7 @@ mod tests {
}

#[bench]
fn bench_big_bitv_small(b: &mut BenchHarness) {
fn bench_big_bitv_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = BigBitv::new(vec!(0));
b.iter(|| {
Expand All @@ -1587,7 +1587,7 @@ mod tests {
}

#[bench]
fn bench_big_bitv_big(b: &mut BenchHarness) {
fn bench_big_bitv_big(b: &mut Bencher) {
let mut r = rng();
let mut storage = vec!();
storage.grow(BENCH_BITS / uint::BITS, &0u);
Expand All @@ -1599,7 +1599,7 @@ mod tests {
}

#[bench]
fn bench_bitv_big(b: &mut BenchHarness) {
fn bench_bitv_big(b: &mut Bencher) {
let mut r = rng();
let mut bitv = Bitv::new(BENCH_BITS, false);
b.iter(|| {
Expand All @@ -1609,7 +1609,7 @@ mod tests {
}

#[bench]
fn bench_bitv_small(b: &mut BenchHarness) {
fn bench_bitv_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = Bitv::new(uint::BITS, false);
b.iter(|| {
Expand All @@ -1619,7 +1619,7 @@ mod tests {
}

#[bench]
fn bench_bitv_set_small(b: &mut BenchHarness) {
fn bench_bitv_set_small(b: &mut Bencher) {
let mut r = rng();
let mut bitv = BitvSet::new();
b.iter(|| {
Expand All @@ -1629,7 +1629,7 @@ mod tests {
}

#[bench]
fn bench_bitv_set_big(b: &mut BenchHarness) {
fn bench_bitv_set_big(b: &mut Bencher) {
let mut r = rng();
let mut bitv = BitvSet::new();
b.iter(|| {
Expand All @@ -1639,7 +1639,7 @@ mod tests {
}

#[bench]
fn bench_bitv_big_union(b: &mut BenchHarness) {
fn bench_bitv_big_union(b: &mut Bencher) {
let mut b1 = Bitv::new(BENCH_BITS, false);
let b2 = Bitv::new(BENCH_BITS, false);
b.iter(|| {
Expand All @@ -1648,7 +1648,7 @@ mod tests {
}

#[bench]
fn bench_btv_small_iter(b: &mut BenchHarness) {
fn bench_btv_small_iter(b: &mut Bencher) {
let bitv = Bitv::new(uint::BITS, false);
b.iter(|| {
let mut _sum = 0;
Expand All @@ -1659,7 +1659,7 @@ mod tests {
}

#[bench]
fn bench_bitv_big_iter(b: &mut BenchHarness) {
fn bench_bitv_big_iter(b: &mut Bencher) {
let bitv = Bitv::new(BENCH_BITS, false);
b.iter(|| {
let mut _sum = 0;
Expand All @@ -1670,7 +1670,7 @@ mod tests {
}

#[bench]
fn bench_bitvset_iter(b: &mut BenchHarness) {
fn bench_bitvset_iter(b: &mut Bencher) {
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
|idx| {idx % 3 == 0}));
b.iter(|| {
Expand Down
18 changes: 9 additions & 9 deletions src/libcollections/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ pub trait Deque<T> : Mutable {
#[cfg(test)]
pub mod bench {
extern crate test;
use self::test::BenchHarness;
use self::test::Bencher;
use std::container::MutableMap;
use rand;
use rand::Rng;

pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
b: &mut Bencher) {
// setup
let mut rng = rand::weak_rng();

Expand All @@ -59,7 +59,7 @@ pub mod bench {
}

// measure
bh.iter(|| {
b.iter(|| {
let k = rng.gen::<uint>() % n;
map.insert(k, 1);
map.remove(&k);
Expand All @@ -68,7 +68,7 @@ pub mod bench {

pub fn insert_seq_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
b: &mut Bencher) {
// setup
map.clear();
for i in range(0u, n) {
Expand All @@ -77,7 +77,7 @@ pub mod bench {

// measure
let mut i = 1;
bh.iter(|| {
b.iter(|| {
map.insert(i, 1);
map.remove(&i);
i = (i + 2) % n;
Expand All @@ -86,7 +86,7 @@ pub mod bench {

pub fn find_rand_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
b: &mut Bencher) {
// setup
let mut rng = rand::weak_rng();
let mut keys = Vec::from_fn(n, |_| rng.gen::<uint>() % n);
Expand All @@ -99,23 +99,23 @@ pub mod bench {

// measure
let mut i = 0;
bh.iter(|| {
b.iter(|| {
map.find(keys.get(i));
i = (i + 1) % n;
})
}

pub fn find_seq_n<M:MutableMap<uint,uint>>(n: uint,
map: &mut M,
bh: &mut BenchHarness) {
b: &mut Bencher) {
// setup
for i in range(0u, n) {
map.insert(i, 1);
}

// measure
let mut i = 0;
bh.iter(|| {
b.iter(|| {
let x = map.find(&i);
i = (i + 1) % n;
x
Expand Down
Loading