Skip to content

Commit 8a4ee7b

Browse files
committed
auto merge of #13236 : liigo/rust/rename-benchharness, r=alexcrichton
Closes #12640 based on PR #13030, rebased, and passed all tests.
2 parents b8ef9fd + a38888e commit 8a4ee7b

38 files changed

+482
-484
lines changed

src/doc/guide-testing.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ runner.
170170

171171
The type signature of a benchmark function differs from a unit test:
172172
it takes a mutable reference to type
173-
`test::BenchHarness`. Inside the benchmark function, any
173+
`test::Bencher`. Inside the benchmark function, any
174174
time-variable or "setup" code should execute first, followed by a call
175175
to `iter` on the benchmark harness, passing a closure that contains
176176
the portion of the benchmark you wish to actually measure the
@@ -189,16 +189,16 @@ For example:
189189
extern crate test;
190190
191191
use std::slice;
192-
use test::BenchHarness;
192+
use test::Bencher;
193193
194194
#[bench]
195-
fn bench_sum_1024_ints(b: &mut BenchHarness) {
195+
fn bench_sum_1024_ints(b: &mut Bencher) {
196196
let v = slice::from_fn(1024, |n| n);
197197
b.iter(|| {v.iter().fold(0, |old, new| old + *new);} );
198198
}
199199
200200
#[bench]
201-
fn initialise_a_vector(b: &mut BenchHarness) {
201+
fn initialise_a_vector(b: &mut Bencher) {
202202
b.iter(|| {slice::from_elem(1024, 0u64);} );
203203
b.bytes = 1024 * 8;
204204
}
@@ -249,11 +249,11 @@ it entirely.
249249
~~~
250250
# #[allow(unused_imports)];
251251
extern crate test;
252-
use test::BenchHarness;
252+
use test::Bencher;
253253
254254
#[bench]
255-
fn bench_xor_1000_ints(bh: &mut BenchHarness) {
256-
bh.iter(|| {
255+
fn bench_xor_1000_ints(b: &mut Bencher) {
256+
b.iter(|| {
257257
range(0, 1000).fold(0, |old, new| old ^ new);
258258
});
259259
}

src/libarena/lib.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ impl<T> Drop for TypedArena<T> {
484484
#[cfg(test)]
485485
mod tests {
486486
extern crate test;
487-
488-
489-
use self::test::BenchHarness;
487+
use self::test::Bencher;
490488
use super::{Arena, TypedArena};
491489

492490
struct Point {
@@ -508,9 +506,9 @@ mod tests {
508506
}
509507

510508
#[bench]
511-
pub fn bench_copy(bh: &mut BenchHarness) {
509+
pub fn bench_copy(b: &mut Bencher) {
512510
let arena = TypedArena::new();
513-
bh.iter(|| {
511+
b.iter(|| {
514512
arena.alloc(Point {
515513
x: 1,
516514
y: 2,
@@ -520,8 +518,8 @@ mod tests {
520518
}
521519

522520
#[bench]
523-
pub fn bench_copy_nonarena(bh: &mut BenchHarness) {
524-
bh.iter(|| {
521+
pub fn bench_copy_nonarena(b: &mut Bencher) {
522+
b.iter(|| {
525523
~Point {
526524
x: 1,
527525
y: 2,
@@ -531,9 +529,9 @@ mod tests {
531529
}
532530

533531
#[bench]
534-
pub fn bench_copy_old_arena(bh: &mut BenchHarness) {
532+
pub fn bench_copy_old_arena(b: &mut Bencher) {
535533
let arena = Arena::new();
536-
bh.iter(|| {
534+
b.iter(|| {
537535
arena.alloc(|| {
538536
Point {
539537
x: 1,
@@ -561,9 +559,9 @@ mod tests {
561559
}
562560

563561
#[bench]
564-
pub fn bench_noncopy(bh: &mut BenchHarness) {
562+
pub fn bench_noncopy(b: &mut Bencher) {
565563
let arena = TypedArena::new();
566-
bh.iter(|| {
564+
b.iter(|| {
567565
arena.alloc(Noncopy {
568566
string: ~"hello world",
569567
array: vec!( 1, 2, 3, 4, 5 ),
@@ -572,8 +570,8 @@ mod tests {
572570
}
573571

574572
#[bench]
575-
pub fn bench_noncopy_nonarena(bh: &mut BenchHarness) {
576-
bh.iter(|| {
573+
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
574+
b.iter(|| {
577575
~Noncopy {
578576
string: ~"hello world",
579577
array: vec!( 1, 2, 3, 4, 5 ),
@@ -582,9 +580,9 @@ mod tests {
582580
}
583581

584582
#[bench]
585-
pub fn bench_noncopy_old_arena(bh: &mut BenchHarness) {
583+
pub fn bench_noncopy_old_arena(b: &mut Bencher) {
586584
let arena = Arena::new();
587-
bh.iter(|| {
585+
b.iter(|| {
588586
arena.alloc(|| Noncopy {
589587
string: ~"hello world",
590588
array: vec!( 1, 2, 3, 4, 5 ),

src/libcollections/bitv.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ impl<'a> Iterator<uint> for BitPositions<'a> {
939939
#[cfg(test)]
940940
mod tests {
941941
extern crate test;
942-
use self::test::BenchHarness;
942+
use self::test::Bencher;
943943

944944
use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn,
945945
from_bytes};
@@ -1557,7 +1557,7 @@ mod tests {
15571557
}
15581558

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

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

15791579
#[bench]
1580-
fn bench_big_bitv_small(b: &mut BenchHarness) {
1580+
fn bench_big_bitv_small(b: &mut Bencher) {
15811581
let mut r = rng();
15821582
let mut bitv = BigBitv::new(~[0]);
15831583
b.iter(|| {
@@ -1587,7 +1587,7 @@ mod tests {
15871587
}
15881588

15891589
#[bench]
1590-
fn bench_big_bitv_big(b: &mut BenchHarness) {
1590+
fn bench_big_bitv_big(b: &mut Bencher) {
15911591
let mut r = rng();
15921592
let mut storage = ~[];
15931593
storage.grow(BENCH_BITS / uint::BITS, &0u);
@@ -1599,7 +1599,7 @@ mod tests {
15991599
}
16001600

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

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

16211621
#[bench]
1622-
fn bench_bitv_set_small(b: &mut BenchHarness) {
1622+
fn bench_bitv_set_small(b: &mut Bencher) {
16231623
let mut r = rng();
16241624
let mut bitv = BitvSet::new();
16251625
b.iter(|| {
@@ -1629,7 +1629,7 @@ mod tests {
16291629
}
16301630

16311631
#[bench]
1632-
fn bench_bitv_set_big(b: &mut BenchHarness) {
1632+
fn bench_bitv_set_big(b: &mut Bencher) {
16331633
let mut r = rng();
16341634
let mut bitv = BitvSet::new();
16351635
b.iter(|| {
@@ -1639,7 +1639,7 @@ mod tests {
16391639
}
16401640

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

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

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

16721672
#[bench]
1673-
fn bench_bitvset_iter(b: &mut BenchHarness) {
1673+
fn bench_bitvset_iter(b: &mut Bencher) {
16741674
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
16751675
|idx| {idx % 3 == 0}));
16761676
b.iter(|| {

src/libcollections/deque.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ pub trait Deque<T> : Mutable {
4242
#[cfg(test)]
4343
pub mod bench {
4444
extern crate test;
45-
use self::test::BenchHarness;
45+
use self::test::Bencher;
4646
use std::container::MutableMap;
4747
use std::slice;
4848
use rand;
4949
use rand::Rng;
5050

5151
pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
5252
map: &mut M,
53-
bh: &mut BenchHarness) {
53+
b: &mut Bencher) {
5454
// setup
5555
let mut rng = rand::XorShiftRng::new();
5656

@@ -60,7 +60,7 @@ pub mod bench {
6060
}
6161

6262
// measure
63-
bh.iter(|| {
63+
b.iter(|| {
6464
let k = rng.gen::<uint>() % n;
6565
map.insert(k, 1);
6666
map.remove(&k);
@@ -69,7 +69,7 @@ pub mod bench {
6969

7070
pub fn insert_seq_n<M:MutableMap<uint,uint>>(n: uint,
7171
map: &mut M,
72-
bh: &mut BenchHarness) {
72+
b: &mut Bencher) {
7373
// setup
7474
map.clear();
7575
for i in range(0u, n) {
@@ -78,7 +78,7 @@ pub mod bench {
7878

7979
// measure
8080
let mut i = 1;
81-
bh.iter(|| {
81+
b.iter(|| {
8282
map.insert(i, 1);
8383
map.remove(&i);
8484
i = (i + 2) % n;
@@ -87,7 +87,7 @@ pub mod bench {
8787

8888
pub fn find_rand_n<M:MutableMap<uint,uint>>(n: uint,
8989
map: &mut M,
90-
bh: &mut BenchHarness) {
90+
b: &mut Bencher) {
9191
// setup
9292
let mut rng = rand::XorShiftRng::new();
9393
let mut keys = slice::from_fn(n, |_| rng.gen::<uint>() % n);
@@ -100,23 +100,23 @@ pub mod bench {
100100

101101
// measure
102102
let mut i = 0;
103-
bh.iter(|| {
103+
b.iter(|| {
104104
map.find(&(keys[i]));
105105
i = (i + 1) % n;
106106
})
107107
}
108108

109109
pub fn find_seq_n<M:MutableMap<uint,uint>>(n: uint,
110110
map: &mut M,
111-
bh: &mut BenchHarness) {
111+
b: &mut Bencher) {
112112
// setup
113113
for i in range(0u, n) {
114114
map.insert(i, 1);
115115
}
116116

117117
// measure
118118
let mut i = 0;
119-
bh.iter(|| {
119+
b.iter(|| {
120120
let x = map.find(&i);
121121
i = (i + 1) % n;
122122
x

0 commit comments

Comments
 (0)