Skip to content

Commit 8b6091e

Browse files
committed
auto merge of #13236 : liigo/rust/rename-benchharness, r=huonw
Closes #12640 based on PR #13030, rebased, and passed all tests.
2 parents 65abf96 + 408f484 commit 8b6091e

39 files changed

+483
-485
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
@@ -481,9 +481,7 @@ impl<T> Drop for TypedArena<T> {
481481
#[cfg(test)]
482482
mod tests {
483483
extern crate test;
484-
485-
486-
use self::test::BenchHarness;
484+
use self::test::Bencher;
487485
use super::{Arena, TypedArena};
488486

489487
struct Point {
@@ -505,9 +503,9 @@ mod tests {
505503
}
506504

507505
#[bench]
508-
pub fn bench_copy(bh: &mut BenchHarness) {
506+
pub fn bench_copy(b: &mut Bencher) {
509507
let arena = TypedArena::new();
510-
bh.iter(|| {
508+
b.iter(|| {
511509
arena.alloc(Point {
512510
x: 1,
513511
y: 2,
@@ -517,8 +515,8 @@ mod tests {
517515
}
518516

519517
#[bench]
520-
pub fn bench_copy_nonarena(bh: &mut BenchHarness) {
521-
bh.iter(|| {
518+
pub fn bench_copy_nonarena(b: &mut Bencher) {
519+
b.iter(|| {
522520
~Point {
523521
x: 1,
524522
y: 2,
@@ -528,9 +526,9 @@ mod tests {
528526
}
529527

530528
#[bench]
531-
pub fn bench_copy_old_arena(bh: &mut BenchHarness) {
529+
pub fn bench_copy_old_arena(b: &mut Bencher) {
532530
let arena = Arena::new();
533-
bh.iter(|| {
531+
b.iter(|| {
534532
arena.alloc(|| {
535533
Point {
536534
x: 1,
@@ -558,9 +556,9 @@ mod tests {
558556
}
559557

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

571569
#[bench]
572-
pub fn bench_noncopy_nonarena(bh: &mut BenchHarness) {
573-
bh.iter(|| {
570+
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
571+
b.iter(|| {
574572
~Noncopy {
575573
string: ~"hello world",
576574
array: vec!( 1, 2, 3, 4, 5 ),
@@ -579,9 +577,9 @@ mod tests {
579577
}
580578

581579
#[bench]
582-
pub fn bench_noncopy_old_arena(bh: &mut BenchHarness) {
580+
pub fn bench_noncopy_old_arena(b: &mut Bencher) {
583581
let arena = Arena::new();
584-
bh.iter(|| {
582+
b.iter(|| {
585583
arena.alloc(|| Noncopy {
586584
string: ~"hello world",
587585
array: vec!( 1, 2, 3, 4, 5 ),

src/libcollections/bitv.rs

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

945945
use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn,
946946
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(vec!(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 = vec!();
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,14 +42,14 @@ 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 rand;
4848
use rand::Rng;
4949

5050
pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
5151
map: &mut M,
52-
bh: &mut BenchHarness) {
52+
b: &mut Bencher) {
5353
// setup
5454
let mut rng = rand::weak_rng();
5555

@@ -59,7 +59,7 @@ pub mod bench {
5959
}
6060

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

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

7878
// measure
7979
let mut i = 1;
80-
bh.iter(|| {
80+
b.iter(|| {
8181
map.insert(i, 1);
8282
map.remove(&i);
8383
i = (i + 2) % n;
@@ -86,7 +86,7 @@ pub mod bench {
8686

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

100100
// measure
101101
let mut i = 0;
102-
bh.iter(|| {
102+
b.iter(|| {
103103
map.find(keys.get(i));
104104
i = (i + 1) % n;
105105
})
106106
}
107107

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

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

0 commit comments

Comments
 (0)