Skip to content

rename test::BenchHarness to test::Bencher #13030

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 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 @@ -192,13 +192,13 @@ use std::slice;
use test::BenchHarness;

#[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
26 changes: 13 additions & 13 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,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 @@ -511,9 +511,9 @@ mod tests {
}

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

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

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

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

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

#[bench]
pub fn bench_nonpod_old_arena(bh: &mut BenchHarness) {
pub fn bench_nonpod_old_arena(b: &mut Bencher) {
let arena = Arena::new();
bh.iter(|| {
b.iter(|| {
arena.alloc(|| Nonpod {
string: ~"hello world",
array: ~[ 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 @@ -939,7 +939,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(~[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 = ~[];
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,15 +42,15 @@ 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 std::slice;
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::XorShiftRng::new();

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

// measure
bh.iter(|| {
b.iter(|| {
let k = rng.gen::<uint>() % n;
map.insert(k, 1);
map.remove(&k);
Expand All @@ -69,7 +69,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 @@ -78,7 +78,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 @@ -87,7 +87,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::XorShiftRng::new();
let mut keys = slice::from_fn(n, |_| rng.gen::<uint>() % n);
Expand All @@ -100,23 +100,23 @@ pub mod bench {

// measure
let mut i = 0;
bh.iter(|| {
b.iter(|| {
map.find(&(keys[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