auto merge of #13236 : liigo/rust/rename-benchharness, r=huonw
Closes #12640 based on PR #13030, rebased, and passed all tests.
This commit is contained in:
commit
8b6091e8f1
@ -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
|
||||
@ -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;
|
||||
}
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -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,
|
||||
@ -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,
|
||||
@ -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,
|
||||
@ -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 ),
|
||||
@ -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 ),
|
||||
@ -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 ),
|
||||
|
@ -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};
|
||||
@ -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(|| {
|
||||
@ -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(|| {
|
||||
@ -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(|| {
|
||||
@ -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);
|
||||
@ -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(|| {
|
||||
@ -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(|| {
|
||||
@ -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(|| {
|
||||
@ -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(|| {
|
||||
@ -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(|| {
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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(|| {
|
||||
|
@ -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();
|
||||
|
||||
@ -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);
|
||||
@ -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) {
|
||||
@ -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;
|
||||
@ -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);
|
||||
@ -99,7 +99,7 @@ pub mod bench {
|
||||
|
||||
// measure
|
||||
let mut i = 0;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
map.find(keys.get(i));
|
||||
i = (i + 1) % n;
|
||||
})
|
||||
@ -107,7 +107,7 @@ pub mod bench {
|
||||
|
||||
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);
|
||||
@ -115,7 +115,7 @@ pub mod bench {
|
||||
|
||||
// measure
|
||||
let mut i = 0;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let x = map.find(&i);
|
||||
i = (i + 1) % n;
|
||||
x
|
||||
|
@ -631,7 +631,7 @@ impl<A: Clone> Clone for DList<A> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use deque::Deque;
|
||||
use rand;
|
||||
use super::{DList, Node, ListInsertion};
|
||||
@ -1082,7 +1082,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_collect_into(b: &mut test::BenchHarness) {
|
||||
fn bench_collect_into(b: &mut test::Bencher) {
|
||||
let v = &[0, ..64];
|
||||
b.iter(|| {
|
||||
let _: DList<int> = v.iter().map(|x| *x).collect();
|
||||
@ -1090,7 +1090,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_front(b: &mut test::BenchHarness) {
|
||||
fn bench_push_front(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
b.iter(|| {
|
||||
m.push_front(0);
|
||||
@ -1098,7 +1098,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_back(b: &mut test::BenchHarness) {
|
||||
fn bench_push_back(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
b.iter(|| {
|
||||
m.push_back(0);
|
||||
@ -1106,7 +1106,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_back_pop_back(b: &mut test::BenchHarness) {
|
||||
fn bench_push_back_pop_back(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
b.iter(|| {
|
||||
m.push_back(0);
|
||||
@ -1115,7 +1115,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_front_pop_front(b: &mut test::BenchHarness) {
|
||||
fn bench_push_front_pop_front(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
b.iter(|| {
|
||||
m.push_front(0);
|
||||
@ -1124,7 +1124,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rotate_forward(b: &mut test::BenchHarness) {
|
||||
fn bench_rotate_forward(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
m.push_front(0);
|
||||
m.push_front(1);
|
||||
@ -1134,7 +1134,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_rotate_backward(b: &mut test::BenchHarness) {
|
||||
fn bench_rotate_backward(b: &mut test::Bencher) {
|
||||
let mut m: DList<int> = DList::new();
|
||||
m.push_front(0);
|
||||
m.push_front(1);
|
||||
@ -1144,7 +1144,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_iter(b: &mut test::BenchHarness) {
|
||||
fn bench_iter(b: &mut test::Bencher) {
|
||||
let v = &[0, ..128];
|
||||
let m: DList<int> = v.iter().map(|&x|x).collect();
|
||||
b.iter(|| {
|
||||
@ -1152,7 +1152,7 @@ mod tests {
|
||||
})
|
||||
}
|
||||
#[bench]
|
||||
fn bench_iter_mut(b: &mut test::BenchHarness) {
|
||||
fn bench_iter_mut(b: &mut test::Bencher) {
|
||||
let v = &[0, ..128];
|
||||
let mut m: DList<int> = v.iter().map(|&x|x).collect();
|
||||
b.iter(|| {
|
||||
@ -1160,7 +1160,7 @@ mod tests {
|
||||
})
|
||||
}
|
||||
#[bench]
|
||||
fn bench_iter_rev(b: &mut test::BenchHarness) {
|
||||
fn bench_iter_rev(b: &mut test::Bencher) {
|
||||
let v = &[0, ..128];
|
||||
let m: DList<int> = v.iter().map(|&x|x).collect();
|
||||
b.iter(|| {
|
||||
@ -1168,7 +1168,7 @@ mod tests {
|
||||
})
|
||||
}
|
||||
#[bench]
|
||||
fn bench_iter_mut_rev(b: &mut test::BenchHarness) {
|
||||
fn bench_iter_mut_rev(b: &mut test::Bencher) {
|
||||
let v = &[0, ..128];
|
||||
let mut m: DList<int> = v.iter().map(|&x|x).collect();
|
||||
b.iter(|| {
|
||||
|
@ -2246,11 +2246,11 @@ mod test_set {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use std::iter::{range_inclusive};
|
||||
|
||||
#[bench]
|
||||
fn insert(b: &mut BenchHarness) {
|
||||
fn insert(b: &mut Bencher) {
|
||||
use super::HashMap;
|
||||
|
||||
let mut m = HashMap::new();
|
||||
@ -2268,7 +2268,7 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn find_existing(b: &mut BenchHarness) {
|
||||
fn find_existing(b: &mut Bencher) {
|
||||
use super::HashMap;
|
||||
|
||||
let mut m = HashMap::new();
|
||||
@ -2283,7 +2283,7 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn find_nonexisting(b: &mut BenchHarness) {
|
||||
fn find_nonexisting(b: &mut Bencher) {
|
||||
use super::HashMap;
|
||||
|
||||
let mut m = HashMap::new();
|
||||
@ -2298,7 +2298,7 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn hashmap_as_queue(b: &mut BenchHarness) {
|
||||
fn hashmap_as_queue(b: &mut Bencher) {
|
||||
use super::HashMap;
|
||||
|
||||
let mut m = HashMap::new();
|
||||
@ -2317,7 +2317,7 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn find_pop_insert(b: &mut BenchHarness) {
|
||||
fn find_pop_insert(b: &mut Bencher) {
|
||||
use super::HashMap;
|
||||
|
||||
let mut m = HashMap::new();
|
||||
|
@ -404,7 +404,7 @@ impl<A> Extendable<A> for RingBuf<A> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use deque::Deque;
|
||||
use std::clone::Clone;
|
||||
use std::cmp::Eq;
|
||||
@ -546,14 +546,14 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_new(b: &mut test::BenchHarness) {
|
||||
fn bench_new(b: &mut test::Bencher) {
|
||||
b.iter(|| {
|
||||
let _: RingBuf<u64> = RingBuf::new();
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_back(b: &mut test::BenchHarness) {
|
||||
fn bench_push_back(b: &mut test::Bencher) {
|
||||
let mut deq = RingBuf::new();
|
||||
b.iter(|| {
|
||||
deq.push_back(0);
|
||||
@ -561,7 +561,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_front(b: &mut test::BenchHarness) {
|
||||
fn bench_push_front(b: &mut test::Bencher) {
|
||||
let mut deq = RingBuf::new();
|
||||
b.iter(|| {
|
||||
deq.push_front(0);
|
||||
@ -569,7 +569,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_grow(b: &mut test::BenchHarness) {
|
||||
fn bench_grow(b: &mut test::Bencher) {
|
||||
let mut deq = RingBuf::new();
|
||||
b.iter(|| {
|
||||
for _ in range(0, 65) {
|
||||
|
@ -476,59 +476,59 @@ mod test_map {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use super::SmallIntMap;
|
||||
use deque::bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n};
|
||||
|
||||
// Find seq
|
||||
#[bench]
|
||||
pub fn insert_rand_100(bh: &mut BenchHarness) {
|
||||
pub fn insert_rand_100(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
insert_rand_n(100, &mut m, bh);
|
||||
insert_rand_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn insert_rand_10_000(bh: &mut BenchHarness) {
|
||||
pub fn insert_rand_10_000(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
insert_rand_n(10_000, &mut m, bh);
|
||||
insert_rand_n(10_000, &mut m, b);
|
||||
}
|
||||
|
||||
// Insert seq
|
||||
#[bench]
|
||||
pub fn insert_seq_100(bh: &mut BenchHarness) {
|
||||
pub fn insert_seq_100(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
insert_seq_n(100, &mut m, bh);
|
||||
insert_seq_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn insert_seq_10_000(bh: &mut BenchHarness) {
|
||||
pub fn insert_seq_10_000(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
insert_seq_n(10_000, &mut m, bh);
|
||||
insert_seq_n(10_000, &mut m, b);
|
||||
}
|
||||
|
||||
// Find rand
|
||||
#[bench]
|
||||
pub fn find_rand_100(bh: &mut BenchHarness) {
|
||||
pub fn find_rand_100(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
find_rand_n(100, &mut m, bh);
|
||||
find_rand_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn find_rand_10_000(bh: &mut BenchHarness) {
|
||||
pub fn find_rand_10_000(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
find_rand_n(10_000, &mut m, bh);
|
||||
find_rand_n(10_000, &mut m, b);
|
||||
}
|
||||
|
||||
// Find seq
|
||||
#[bench]
|
||||
pub fn find_seq_100(bh: &mut BenchHarness) {
|
||||
pub fn find_seq_100(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
find_seq_n(100, &mut m, bh);
|
||||
find_seq_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn find_seq_10_000(bh: &mut BenchHarness) {
|
||||
pub fn find_seq_10_000(b: &mut Bencher) {
|
||||
let mut m : SmallIntMap<uint> = SmallIntMap::new();
|
||||
find_seq_n(10_000, &mut m, bh);
|
||||
find_seq_n(10_000, &mut m, b);
|
||||
}
|
||||
}
|
||||
|
@ -1428,60 +1428,60 @@ mod test_treemap {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use super::TreeMap;
|
||||
use deque::bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n};
|
||||
|
||||
// Find seq
|
||||
#[bench]
|
||||
pub fn insert_rand_100(bh: &mut BenchHarness) {
|
||||
pub fn insert_rand_100(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
insert_rand_n(100, &mut m, bh);
|
||||
insert_rand_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn insert_rand_10_000(bh: &mut BenchHarness) {
|
||||
pub fn insert_rand_10_000(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
insert_rand_n(10_000, &mut m, bh);
|
||||
insert_rand_n(10_000, &mut m, b);
|
||||
}
|
||||
|
||||
// Insert seq
|
||||
#[bench]
|
||||
pub fn insert_seq_100(bh: &mut BenchHarness) {
|
||||
pub fn insert_seq_100(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
insert_seq_n(100, &mut m, bh);
|
||||
insert_seq_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn insert_seq_10_000(bh: &mut BenchHarness) {
|
||||
pub fn insert_seq_10_000(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
insert_seq_n(10_000, &mut m, bh);
|
||||
insert_seq_n(10_000, &mut m, b);
|
||||
}
|
||||
|
||||
// Find rand
|
||||
#[bench]
|
||||
pub fn find_rand_100(bh: &mut BenchHarness) {
|
||||
pub fn find_rand_100(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_rand_n(100, &mut m, bh);
|
||||
find_rand_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn find_rand_10_000(bh: &mut BenchHarness) {
|
||||
pub fn find_rand_10_000(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_rand_n(10_000, &mut m, bh);
|
||||
find_rand_n(10_000, &mut m, b);
|
||||
}
|
||||
|
||||
// Find seq
|
||||
#[bench]
|
||||
pub fn find_seq_100(bh: &mut BenchHarness) {
|
||||
pub fn find_seq_100(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_seq_n(100, &mut m, bh);
|
||||
find_seq_n(100, &mut m, b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn find_seq_10_000(bh: &mut BenchHarness) {
|
||||
pub fn find_seq_10_000(b: &mut Bencher) {
|
||||
let mut m : TreeMap<uint,uint> = TreeMap::new();
|
||||
find_seq_n(10_000, &mut m, bh);
|
||||
find_seq_n(10_000, &mut m, b);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -913,39 +913,39 @@ mod bench_map {
|
||||
extern crate test;
|
||||
use super::TrieMap;
|
||||
use rand::{weak_rng, Rng};
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_iter_small(bh: &mut BenchHarness) {
|
||||
fn bench_iter_small(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<uint>::new();
|
||||
let mut rng = weak_rng();
|
||||
for _ in range(0, 20) {
|
||||
m.insert(rng.gen(), rng.gen());
|
||||
}
|
||||
|
||||
bh.iter(|| for _ in m.iter() {})
|
||||
b.iter(|| for _ in m.iter() {})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_iter_large(bh: &mut BenchHarness) {
|
||||
fn bench_iter_large(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<uint>::new();
|
||||
let mut rng = weak_rng();
|
||||
for _ in range(0, 1000) {
|
||||
m.insert(rng.gen(), rng.gen());
|
||||
}
|
||||
|
||||
bh.iter(|| for _ in m.iter() {})
|
||||
b.iter(|| for _ in m.iter() {})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_lower_bound(bh: &mut BenchHarness) {
|
||||
fn bench_lower_bound(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<uint>::new();
|
||||
let mut rng = weak_rng();
|
||||
for _ in range(0, 1000) {
|
||||
m.insert(rng.gen(), rng.gen());
|
||||
}
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, 10) {
|
||||
m.lower_bound(rng.gen());
|
||||
}
|
||||
@ -953,14 +953,14 @@ mod bench_map {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_upper_bound(bh: &mut BenchHarness) {
|
||||
fn bench_upper_bound(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<uint>::new();
|
||||
let mut rng = weak_rng();
|
||||
for _ in range(0, 1000) {
|
||||
m.insert(rng.gen(), rng.gen());
|
||||
}
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, 10) {
|
||||
m.upper_bound(rng.gen());
|
||||
}
|
||||
@ -968,22 +968,22 @@ mod bench_map {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_insert_large(bh: &mut BenchHarness) {
|
||||
fn bench_insert_large(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<[uint, .. 10]>::new();
|
||||
let mut rng = weak_rng();
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, 1000) {
|
||||
m.insert(rng.gen(), [1, .. 10]);
|
||||
}
|
||||
})
|
||||
}
|
||||
#[bench]
|
||||
fn bench_insert_large_low_bits(bh: &mut BenchHarness) {
|
||||
fn bench_insert_large_low_bits(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<[uint, .. 10]>::new();
|
||||
let mut rng = weak_rng();
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, 1000) {
|
||||
// only have the last few bits set.
|
||||
m.insert(rng.gen::<uint>() & 0xff_ff, [1, .. 10]);
|
||||
@ -992,22 +992,22 @@ mod bench_map {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_insert_small(bh: &mut BenchHarness) {
|
||||
fn bench_insert_small(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<()>::new();
|
||||
let mut rng = weak_rng();
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, 1000) {
|
||||
m.insert(rng.gen(), ());
|
||||
}
|
||||
})
|
||||
}
|
||||
#[bench]
|
||||
fn bench_insert_small_low_bits(bh: &mut BenchHarness) {
|
||||
fn bench_insert_small_low_bits(b: &mut Bencher) {
|
||||
let mut m = TrieMap::<()>::new();
|
||||
let mut rng = weak_rng();
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, 1000) {
|
||||
// only have the last few bits set.
|
||||
m.insert(rng.gen::<uint>() & 0xff_ff, ());
|
||||
|
@ -2742,7 +2742,7 @@ mod bigint_tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use super::BigUint;
|
||||
use std::iter;
|
||||
use std::mem::replace;
|
||||
@ -2767,35 +2767,35 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn factorial_100(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn factorial_100(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
factorial(100);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn fib_100(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn fib_100(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
fib(100);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str(bh: &mut BenchHarness) {
|
||||
fn to_str(b: &mut Bencher) {
|
||||
let fac = factorial(100);
|
||||
let fib = fib(100);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
fac.to_str();
|
||||
});
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
fib.to_str();
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn shr(bh: &mut BenchHarness) {
|
||||
fn shr(b: &mut Bencher) {
|
||||
let n = { let one : BigUint = One::one(); one << 1000 };
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut m = n.clone();
|
||||
for _ in range(0, 10) {
|
||||
m = m >> 1;
|
||||
|
@ -118,22 +118,22 @@ mod test {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use std::mem::size_of;
|
||||
use {XorShiftRng, RAND_BENCH_N};
|
||||
use super::Exp;
|
||||
use distributions::Sample;
|
||||
|
||||
#[bench]
|
||||
fn rand_exp(bh: &mut BenchHarness) {
|
||||
fn rand_exp(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
let mut exp = Exp::new(2.71828 * 3.14159);
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
exp.sample(&mut rng);
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ mod test {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use std::mem::size_of;
|
||||
use distributions::IndependentSample;
|
||||
use {XorShiftRng, RAND_BENCH_N};
|
||||
@ -374,28 +374,28 @@ mod bench {
|
||||
|
||||
|
||||
#[bench]
|
||||
fn bench_gamma_large_shape(bh: &mut BenchHarness) {
|
||||
fn bench_gamma_large_shape(b: &mut Bencher) {
|
||||
let gamma = Gamma::new(10., 1.0);
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
gamma.ind_sample(&mut rng);
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_gamma_small_shape(bh: &mut BenchHarness) {
|
||||
fn bench_gamma_small_shape(b: &mut Bencher) {
|
||||
let gamma = Gamma::new(0.1, 1.0);
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
gamma.ind_sample(&mut rng);
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
}
|
||||
|
@ -185,22 +185,22 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use std::mem::size_of;
|
||||
use {XorShiftRng, RAND_BENCH_N};
|
||||
use distributions::{Sample};
|
||||
use super::Normal;
|
||||
|
||||
#[bench]
|
||||
fn rand_normal(bh: &mut BenchHarness) {
|
||||
fn rand_normal(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
let mut normal = Normal::new(-2.71828, 3.14159);
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
normal.sample(&mut rng);
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
}
|
||||
|
@ -883,59 +883,59 @@ static RAND_BENCH_N: u64 = 100;
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use {XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N};
|
||||
use std::mem::size_of;
|
||||
|
||||
#[bench]
|
||||
fn rand_xorshift(bh: &mut BenchHarness) {
|
||||
fn rand_xorshift(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
rng.gen::<uint>();
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn rand_isaac(bh: &mut BenchHarness) {
|
||||
fn rand_isaac(b: &mut Bencher) {
|
||||
let mut rng = IsaacRng::new().unwrap();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
rng.gen::<uint>();
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn rand_isaac64(bh: &mut BenchHarness) {
|
||||
fn rand_isaac64(b: &mut Bencher) {
|
||||
let mut rng = Isaac64Rng::new().unwrap();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
rng.gen::<uint>();
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn rand_std(bh: &mut BenchHarness) {
|
||||
fn rand_std(b: &mut Bencher) {
|
||||
let mut rng = StdRng::new().unwrap();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
for _ in range(0, RAND_BENCH_N) {
|
||||
rng.gen::<uint>();
|
||||
}
|
||||
});
|
||||
bh.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
b.bytes = size_of::<uint>() as u64 * RAND_BENCH_N;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn rand_shuffle_100(bh: &mut BenchHarness) {
|
||||
fn rand_shuffle_100(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
let x : &mut[uint] = [1,..100];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
rng.shuffle(x);
|
||||
})
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ fn is_bench_fn(cx: &TestCtxt, i: @ast::Item) -> bool {
|
||||
if has_bench_attr && !has_test_signature(i) {
|
||||
let sess = cx.sess;
|
||||
sess.span_err(i.span, "functions used as benches must have signature \
|
||||
`fn(&mut BenchHarness) -> ()`");
|
||||
`fn(&mut Bencher) -> ()`");
|
||||
}
|
||||
|
||||
return has_bench_attr && has_test_signature(i);
|
||||
|
@ -641,36 +641,36 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use super::{Sha256, FixedBuffer, Digest};
|
||||
|
||||
#[bench]
|
||||
pub fn sha256_10(bh: &mut BenchHarness) {
|
||||
pub fn sha256_10(b: &mut Bencher) {
|
||||
let mut sh = Sha256::new();
|
||||
let bytes = [1u8, ..10];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
sh.input(bytes);
|
||||
});
|
||||
bh.bytes = bytes.len() as u64;
|
||||
b.bytes = bytes.len() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn sha256_1k(bh: &mut BenchHarness) {
|
||||
pub fn sha256_1k(b: &mut Bencher) {
|
||||
let mut sh = Sha256::new();
|
||||
let bytes = [1u8, ..1024];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
sh.input(bytes);
|
||||
});
|
||||
bh.bytes = bytes.len() as u64;
|
||||
b.bytes = bytes.len() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn sha256_64k(bh: &mut BenchHarness) {
|
||||
pub fn sha256_64k(b: &mut Bencher) {
|
||||
let mut sh = Sha256::new();
|
||||
let bytes = [1u8, ..65536];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
sh.input(bytes);
|
||||
});
|
||||
bh.bytes = bytes.len() as u64;
|
||||
b.bytes = bytes.len() as u64;
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ impl<'a> FromBase64 for &'a str {
|
||||
mod tests {
|
||||
extern crate test;
|
||||
extern crate rand;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use base64::{Config, FromBase64, ToBase64, STANDARD, URL_SAFE};
|
||||
|
||||
#[test]
|
||||
@ -347,24 +347,24 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn bench_to_base64(bh: & mut BenchHarness) {
|
||||
pub fn bench_to_base64(b: &mut Bencher) {
|
||||
let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
|
||||
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
s.as_bytes().to_base64(STANDARD);
|
||||
});
|
||||
bh.bytes = s.len() as u64;
|
||||
b.bytes = s.len() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn bench_from_base64(bh: & mut BenchHarness) {
|
||||
pub fn bench_from_base64(b: &mut Bencher) {
|
||||
let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
|
||||
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
|
||||
let b = s.as_bytes().to_base64(STANDARD);
|
||||
bh.iter(|| {
|
||||
b.from_base64().unwrap();
|
||||
let sb = s.as_bytes().to_base64(STANDARD);
|
||||
b.iter(|| {
|
||||
sb.from_base64().unwrap();
|
||||
});
|
||||
bh.bytes = b.len() as u64;
|
||||
b.bytes = sb.len() as u64;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1094,11 +1094,11 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use ebml::reader;
|
||||
|
||||
#[bench]
|
||||
pub fn vuint_at_A_aligned(bh: &mut BenchHarness) {
|
||||
pub fn vuint_at_A_aligned(b: &mut Bencher) {
|
||||
use std::slice;
|
||||
let data = slice::from_fn(4*100, |i| {
|
||||
match i % 2 {
|
||||
@ -1107,7 +1107,7 @@ mod bench {
|
||||
}
|
||||
});
|
||||
let mut sum = 0u;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut i = 0;
|
||||
while i < data.len() {
|
||||
sum += reader::vuint_at(data, i).unwrap().val;
|
||||
@ -1117,7 +1117,7 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn vuint_at_A_unaligned(bh: &mut BenchHarness) {
|
||||
pub fn vuint_at_A_unaligned(b: &mut Bencher) {
|
||||
use std::slice;
|
||||
let data = slice::from_fn(4*100+1, |i| {
|
||||
match i % 2 {
|
||||
@ -1126,7 +1126,7 @@ mod bench {
|
||||
}
|
||||
});
|
||||
let mut sum = 0u;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut i = 1;
|
||||
while i < data.len() {
|
||||
sum += reader::vuint_at(data, i).unwrap().val;
|
||||
@ -1136,7 +1136,7 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn vuint_at_D_aligned(bh: &mut BenchHarness) {
|
||||
pub fn vuint_at_D_aligned(b: &mut Bencher) {
|
||||
use std::slice;
|
||||
let data = slice::from_fn(4*100, |i| {
|
||||
match i % 4 {
|
||||
@ -1146,7 +1146,7 @@ mod bench {
|
||||
}
|
||||
});
|
||||
let mut sum = 0u;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut i = 0;
|
||||
while i < data.len() {
|
||||
sum += reader::vuint_at(data, i).unwrap().val;
|
||||
@ -1156,7 +1156,7 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn vuint_at_D_unaligned(bh: &mut BenchHarness) {
|
||||
pub fn vuint_at_D_unaligned(b: &mut Bencher) {
|
||||
use std::slice;
|
||||
let data = slice::from_fn(4*100+1, |i| {
|
||||
match i % 4 {
|
||||
@ -1166,7 +1166,7 @@ mod bench {
|
||||
}
|
||||
});
|
||||
let mut sum = 0u;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut i = 1;
|
||||
while i < data.len() {
|
||||
sum += reader::vuint_at(data, i).unwrap().val;
|
||||
|
@ -141,7 +141,7 @@ impl<'a> FromHex for &'a str {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use hex::{FromHex, ToHex};
|
||||
|
||||
#[test]
|
||||
@ -190,23 +190,23 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn bench_to_hex(bh: & mut BenchHarness) {
|
||||
pub fn bench_to_hex(b: &mut Bencher) {
|
||||
let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
|
||||
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
s.as_bytes().to_hex();
|
||||
});
|
||||
bh.bytes = s.len() as u64;
|
||||
b.bytes = s.len() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn bench_from_hex(bh: & mut BenchHarness) {
|
||||
pub fn bench_from_hex(b: &mut Bencher) {
|
||||
let s = "イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム \
|
||||
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン";
|
||||
let b = s.as_bytes().to_hex();
|
||||
bh.iter(|| {
|
||||
b.from_hex().unwrap();
|
||||
let sb = s.as_bytes().to_hex();
|
||||
b.iter(|| {
|
||||
sb.from_hex().unwrap();
|
||||
});
|
||||
bh.bytes = b.len() as u64;
|
||||
b.bytes = sb.len() as u64;
|
||||
}
|
||||
}
|
||||
|
@ -306,11 +306,11 @@ mod bench {
|
||||
|
||||
use any::{Any, AnyRefExt};
|
||||
use option::Some;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_as_ref(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn bench_as_ref(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut x = 0; let mut y = &mut x as &mut Any;
|
||||
test::black_box(&mut y);
|
||||
test::black_box(y.as_ref::<int>() == Some(&0));
|
||||
|
@ -670,7 +670,7 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use libc;
|
||||
use prelude::*;
|
||||
|
||||
@ -696,73 +696,73 @@ mod bench {
|
||||
Mary had a little lamb, Little lamb
|
||||
Mary had a little lamb, Little lamb";
|
||||
|
||||
fn bench_to_str(bh: &mut BenchHarness, s: &str) {
|
||||
bh.iter(|| {
|
||||
fn bench_to_str(b: &mut Bencher, s: &str) {
|
||||
b.iter(|| {
|
||||
let c_str = s.to_c_str();
|
||||
c_str.with_ref(|c_str_buf| check(s, c_str_buf))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_to_c_str_short(bh: &mut BenchHarness) {
|
||||
bench_to_str(bh, s_short)
|
||||
fn bench_to_c_str_short(b: &mut Bencher) {
|
||||
bench_to_str(b, s_short)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_to_c_str_medium(bh: &mut BenchHarness) {
|
||||
bench_to_str(bh, s_medium)
|
||||
fn bench_to_c_str_medium(b: &mut Bencher) {
|
||||
bench_to_str(b, s_medium)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_to_c_str_long(bh: &mut BenchHarness) {
|
||||
bench_to_str(bh, s_long)
|
||||
fn bench_to_c_str_long(b: &mut Bencher) {
|
||||
bench_to_str(b, s_long)
|
||||
}
|
||||
|
||||
fn bench_to_c_str_unchecked(bh: &mut BenchHarness, s: &str) {
|
||||
bh.iter(|| {
|
||||
fn bench_to_c_str_unchecked(b: &mut Bencher, s: &str) {
|
||||
b.iter(|| {
|
||||
let c_str = unsafe { s.to_c_str_unchecked() };
|
||||
c_str.with_ref(|c_str_buf| check(s, c_str_buf))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_to_c_str_unchecked_short(bh: &mut BenchHarness) {
|
||||
bench_to_c_str_unchecked(bh, s_short)
|
||||
fn bench_to_c_str_unchecked_short(b: &mut Bencher) {
|
||||
bench_to_c_str_unchecked(b, s_short)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_to_c_str_unchecked_medium(bh: &mut BenchHarness) {
|
||||
bench_to_c_str_unchecked(bh, s_medium)
|
||||
fn bench_to_c_str_unchecked_medium(b: &mut Bencher) {
|
||||
bench_to_c_str_unchecked(b, s_medium)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_to_c_str_unchecked_long(bh: &mut BenchHarness) {
|
||||
bench_to_c_str_unchecked(bh, s_long)
|
||||
fn bench_to_c_str_unchecked_long(b: &mut Bencher) {
|
||||
bench_to_c_str_unchecked(b, s_long)
|
||||
}
|
||||
|
||||
fn bench_with_c_str(bh: &mut BenchHarness, s: &str) {
|
||||
bh.iter(|| {
|
||||
fn bench_with_c_str(b: &mut Bencher, s: &str) {
|
||||
b.iter(|| {
|
||||
s.with_c_str(|c_str_buf| check(s, c_str_buf))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_with_c_str_short(bh: &mut BenchHarness) {
|
||||
bench_with_c_str(bh, s_short)
|
||||
fn bench_with_c_str_short(b: &mut Bencher) {
|
||||
bench_with_c_str(b, s_short)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_with_c_str_medium(bh: &mut BenchHarness) {
|
||||
bench_with_c_str(bh, s_medium)
|
||||
fn bench_with_c_str_medium(b: &mut Bencher) {
|
||||
bench_with_c_str(b, s_medium)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_with_c_str_long(bh: &mut BenchHarness) {
|
||||
bench_with_c_str(bh, s_long)
|
||||
fn bench_with_c_str_long(b: &mut Bencher) {
|
||||
bench_with_c_str(b, s_long)
|
||||
}
|
||||
|
||||
fn bench_with_c_str_unchecked(bh: &mut BenchHarness, s: &str) {
|
||||
bh.iter(|| {
|
||||
fn bench_with_c_str_unchecked(b: &mut Bencher, s: &str) {
|
||||
b.iter(|| {
|
||||
unsafe {
|
||||
s.with_c_str_unchecked(|c_str_buf| check(s, c_str_buf))
|
||||
}
|
||||
@ -770,17 +770,17 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_with_c_str_unchecked_short(bh: &mut BenchHarness) {
|
||||
bench_with_c_str_unchecked(bh, s_short)
|
||||
fn bench_with_c_str_unchecked_short(b: &mut Bencher) {
|
||||
bench_with_c_str_unchecked(b, s_short)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_with_c_str_unchecked_medium(bh: &mut BenchHarness) {
|
||||
bench_with_c_str_unchecked(bh, s_medium)
|
||||
fn bench_with_c_str_unchecked_medium(b: &mut Bencher) {
|
||||
bench_with_c_str_unchecked(b, s_medium)
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_with_c_str_unchecked_long(bh: &mut BenchHarness) {
|
||||
bench_with_c_str_unchecked(bh, s_long)
|
||||
fn bench_with_c_str_unchecked_long(b: &mut Bencher) {
|
||||
bench_with_c_str_unchecked(b, s_long)
|
||||
}
|
||||
}
|
||||
|
@ -394,74 +394,74 @@ mod bench {
|
||||
extern crate test;
|
||||
|
||||
mod uint {
|
||||
use super::test::BenchHarness;
|
||||
use super::test::Bencher;
|
||||
use fmt::radix;
|
||||
use rand::{XorShiftRng, Rng};
|
||||
|
||||
#[bench]
|
||||
fn format_bin(bh: &mut BenchHarness) {
|
||||
fn format_bin(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:t}", rng.gen::<uint>()); })
|
||||
b.iter(|| { format!("{:t}", rng.gen::<uint>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_oct(bh: &mut BenchHarness) {
|
||||
fn format_oct(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:o}", rng.gen::<uint>()); })
|
||||
b.iter(|| { format!("{:o}", rng.gen::<uint>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_dec(bh: &mut BenchHarness) {
|
||||
fn format_dec(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:u}", rng.gen::<uint>()); })
|
||||
b.iter(|| { format!("{:u}", rng.gen::<uint>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_hex(bh: &mut BenchHarness) {
|
||||
fn format_hex(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:x}", rng.gen::<uint>()); })
|
||||
b.iter(|| { format!("{:x}", rng.gen::<uint>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_base_36(bh: &mut BenchHarness) {
|
||||
fn format_base_36(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{}", radix(rng.gen::<uint>(), 36)); })
|
||||
b.iter(|| { format!("{}", radix(rng.gen::<uint>(), 36)); })
|
||||
}
|
||||
}
|
||||
|
||||
mod int {
|
||||
use super::test::BenchHarness;
|
||||
use super::test::Bencher;
|
||||
use fmt::radix;
|
||||
use rand::{XorShiftRng, Rng};
|
||||
|
||||
#[bench]
|
||||
fn format_bin(bh: &mut BenchHarness) {
|
||||
fn format_bin(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:t}", rng.gen::<int>()); })
|
||||
b.iter(|| { format!("{:t}", rng.gen::<int>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_oct(bh: &mut BenchHarness) {
|
||||
fn format_oct(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:o}", rng.gen::<int>()); })
|
||||
b.iter(|| { format!("{:o}", rng.gen::<int>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_dec(bh: &mut BenchHarness) {
|
||||
fn format_dec(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:d}", rng.gen::<int>()); })
|
||||
b.iter(|| { format!("{:d}", rng.gen::<int>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_hex(bh: &mut BenchHarness) {
|
||||
fn format_hex(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{:x}", rng.gen::<int>()); })
|
||||
b.iter(|| { format!("{:x}", rng.gen::<int>()); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn format_base_36(bh: &mut BenchHarness) {
|
||||
fn format_base_36(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { format!("{}", radix(rng.gen::<int>(), 36)); })
|
||||
b.iter(|| { format!("{}", radix(rng.gen::<int>(), 36)); })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ mod tests {
|
||||
use str::Str;
|
||||
use strbuf::StrBuf;
|
||||
use slice::{Vector, ImmutableVector, OwnedVector};
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
|
||||
use super::super::Hash;
|
||||
use super::{SipState, hash, hash_with_keys};
|
||||
@ -517,9 +517,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_str(bh: &mut BenchHarness) {
|
||||
fn bench_str(b: &mut Bencher) {
|
||||
let s = "foo";
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&s), 16262950014981195938);
|
||||
})
|
||||
}
|
||||
@ -540,13 +540,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_compound_1(bh: &mut BenchHarness) {
|
||||
fn bench_compound_1(b: &mut Bencher) {
|
||||
let compound = Compound {
|
||||
x: 1,
|
||||
y: 2,
|
||||
z: ~"foobarbaz",
|
||||
};
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&compound), 3581836382593270478);
|
||||
})
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ mod test {
|
||||
use prelude::*;
|
||||
use super::*;
|
||||
use super::super::mem::{MemReader, MemWriter, BufReader};
|
||||
use Harness = self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
|
||||
/// A type, free to create, primarily intended for benchmarking creation of
|
||||
/// wrappers that, just for construction, don't need a Reader/Writer that
|
||||
@ -584,22 +584,22 @@ mod test {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_buffered_reader(bh: &mut Harness) {
|
||||
bh.iter(|| {
|
||||
fn bench_buffered_reader(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
BufferedReader::new(NullStream)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_buffered_writer(bh: &mut Harness) {
|
||||
bh.iter(|| {
|
||||
fn bench_buffered_writer(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
BufferedWriter::new(NullStream)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_buffered_stream(bh: &mut Harness) {
|
||||
bh.iter(|| {
|
||||
fn bench_buffered_stream(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
BufferedStream::new(NullStream);
|
||||
});
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ mod test {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use container::Container;
|
||||
|
||||
macro_rules! u64_from_be_bytes_bench_impl(
|
||||
@ -514,7 +514,7 @@ mod bench {
|
||||
|
||||
let data = slice::from_fn($stride*100+$start_index, |i| i as u8);
|
||||
let mut sum = 0u64;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut i = $start_index;
|
||||
while i < data.len() {
|
||||
sum += u64_from_be_bytes(data, i, $size);
|
||||
@ -525,32 +525,32 @@ mod bench {
|
||||
)
|
||||
|
||||
#[bench]
|
||||
fn u64_from_be_bytes_4_aligned(bh: &mut BenchHarness) {
|
||||
fn u64_from_be_bytes_4_aligned(b: &mut Bencher) {
|
||||
u64_from_be_bytes_bench_impl!(4, 4, 0);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn u64_from_be_bytes_4_unaligned(bh: &mut BenchHarness) {
|
||||
fn u64_from_be_bytes_4_unaligned(b: &mut Bencher) {
|
||||
u64_from_be_bytes_bench_impl!(4, 4, 1);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn u64_from_be_bytes_7_aligned(bh: &mut BenchHarness) {
|
||||
fn u64_from_be_bytes_7_aligned(b: &mut Bencher) {
|
||||
u64_from_be_bytes_bench_impl!(7, 8, 0);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn u64_from_be_bytes_7_unaligned(bh: &mut BenchHarness) {
|
||||
fn u64_from_be_bytes_7_unaligned(b: &mut Bencher) {
|
||||
u64_from_be_bytes_bench_impl!(7, 8, 1);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn u64_from_be_bytes_8_aligned(bh: &mut BenchHarness) {
|
||||
fn u64_from_be_bytes_8_aligned(b: &mut Bencher) {
|
||||
u64_from_be_bytes_bench_impl!(8, 8, 0);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn u64_from_be_bytes_8_unaligned(bh: &mut BenchHarness) {
|
||||
fn u64_from_be_bytes_8_unaligned(b: &mut Bencher) {
|
||||
u64_from_be_bytes_bench_impl!(8, 8, 1);
|
||||
}
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use option::{Some,None};
|
||||
|
||||
// Static/dynamic method dispatch
|
||||
@ -383,18 +383,18 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trait_vtable_method_call(bh: &mut BenchHarness) {
|
||||
fn trait_vtable_method_call(b: &mut Bencher) {
|
||||
let s = Struct { field: 10 };
|
||||
let t = &s as &Trait;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
t.method()
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trait_static_method_call(bh: &mut BenchHarness) {
|
||||
fn trait_static_method_call(b: &mut Bencher) {
|
||||
let s = Struct { field: 10 };
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
s.method()
|
||||
});
|
||||
}
|
||||
@ -402,9 +402,9 @@ mod bench {
|
||||
// Overhead of various match forms
|
||||
|
||||
#[bench]
|
||||
fn match_option_some(bh: &mut BenchHarness) {
|
||||
fn match_option_some(b: &mut Bencher) {
|
||||
let x = Some(10);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
match x {
|
||||
Some(y) => y,
|
||||
None => 11
|
||||
@ -413,9 +413,9 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn match_vec_pattern(bh: &mut BenchHarness) {
|
||||
fn match_vec_pattern(b: &mut Bencher) {
|
||||
let x = [1,2,3,4,5,6];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
match x {
|
||||
[1,2,3,..] => 10,
|
||||
_ => 11
|
||||
|
@ -1773,13 +1773,13 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use num;
|
||||
use slice;
|
||||
use prelude::*;
|
||||
|
||||
#[bench]
|
||||
fn bench_pow_function(b: &mut BenchHarness) {
|
||||
fn bench_pow_function(b: &mut Bencher) {
|
||||
let v = slice::from_fn(1024, |n| n);
|
||||
b.iter(|| {v.iter().fold(0, |old, new| num::pow(old, *new));});
|
||||
}
|
||||
|
@ -815,86 +815,86 @@ mod bench {
|
||||
extern crate test;
|
||||
|
||||
mod uint {
|
||||
use super::test::BenchHarness;
|
||||
use super::test::Bencher;
|
||||
use rand::{XorShiftRng, Rng};
|
||||
use num::ToStrRadix;
|
||||
|
||||
#[bench]
|
||||
fn to_str_bin(bh: &mut BenchHarness) {
|
||||
fn to_str_bin(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<uint>().to_str_radix(2); })
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(2); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_oct(bh: &mut BenchHarness) {
|
||||
fn to_str_oct(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<uint>().to_str_radix(8); })
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(8); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_dec(bh: &mut BenchHarness) {
|
||||
fn to_str_dec(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<uint>().to_str_radix(10); })
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(10); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_hex(bh: &mut BenchHarness) {
|
||||
fn to_str_hex(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<uint>().to_str_radix(16); })
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(16); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_base_36(bh: &mut BenchHarness) {
|
||||
fn to_str_base_36(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<uint>().to_str_radix(36); })
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(36); })
|
||||
}
|
||||
}
|
||||
|
||||
mod int {
|
||||
use super::test::BenchHarness;
|
||||
use super::test::Bencher;
|
||||
use rand::{XorShiftRng, Rng};
|
||||
use num::ToStrRadix;
|
||||
|
||||
#[bench]
|
||||
fn to_str_bin(bh: &mut BenchHarness) {
|
||||
fn to_str_bin(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<int>().to_str_radix(2); })
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(2); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_oct(bh: &mut BenchHarness) {
|
||||
fn to_str_oct(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<int>().to_str_radix(8); })
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(8); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_dec(bh: &mut BenchHarness) {
|
||||
fn to_str_dec(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<int>().to_str_radix(10); })
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(10); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_hex(bh: &mut BenchHarness) {
|
||||
fn to_str_hex(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<int>().to_str_radix(16); })
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(16); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_base_36(bh: &mut BenchHarness) {
|
||||
fn to_str_base_36(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { rng.gen::<int>().to_str_radix(36); })
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(36); })
|
||||
}
|
||||
}
|
||||
|
||||
mod f64 {
|
||||
use super::test::BenchHarness;
|
||||
use super::test::Bencher;
|
||||
use rand::{XorShiftRng, Rng};
|
||||
use f64;
|
||||
|
||||
#[bench]
|
||||
fn float_to_str(bh: &mut BenchHarness) {
|
||||
fn float_to_str(b: &mut Bencher) {
|
||||
let mut rng = XorShiftRng::new().unwrap();
|
||||
bh.iter(|| { f64::to_str(rng.gen()); })
|
||||
b.iter(|| { f64::to_str(rng.gen()); })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ pub trait DerefMut<Result>: Deref<Result> {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use ops::Drop;
|
||||
|
||||
// Overhead of dtors
|
||||
@ -566,8 +566,8 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn alloc_obj_with_dtor(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn alloc_obj_with_dtor(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
HasDtor { x : 10 };
|
||||
})
|
||||
}
|
||||
|
@ -1253,127 +1253,127 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
|
||||
#[bench]
|
||||
fn join_home_dir(bh: &mut BenchHarness) {
|
||||
fn join_home_dir(b: &mut Bencher) {
|
||||
let posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.join("home");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn join_abs_path_home_dir(bh: &mut BenchHarness) {
|
||||
fn join_abs_path_home_dir(b: &mut Bencher) {
|
||||
let posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.join("/home");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn join_many_home_dir(bh: &mut BenchHarness) {
|
||||
fn join_many_home_dir(b: &mut Bencher) {
|
||||
let posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.join_many(&["home"]);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn join_many_abs_path_home_dir(bh: &mut BenchHarness) {
|
||||
fn join_many_abs_path_home_dir(b: &mut Bencher) {
|
||||
let posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.join_many(&["/home"]);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn push_home_dir(bh: &mut BenchHarness) {
|
||||
fn push_home_dir(b: &mut Bencher) {
|
||||
let mut posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.push("home");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn push_abs_path_home_dir(bh: &mut BenchHarness) {
|
||||
fn push_abs_path_home_dir(b: &mut Bencher) {
|
||||
let mut posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.push("/home");
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn push_many_home_dir(bh: &mut BenchHarness) {
|
||||
fn push_many_home_dir(b: &mut Bencher) {
|
||||
let mut posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.push_many(&["home"]);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn push_many_abs_path_home_dir(bh: &mut BenchHarness) {
|
||||
fn push_many_abs_path_home_dir(b: &mut Bencher) {
|
||||
let mut posix_path = Path::new("/");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_path.push_many(&["/home"]);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn ends_with_path_home_dir(bh: &mut BenchHarness) {
|
||||
fn ends_with_path_home_dir(b: &mut Bencher) {
|
||||
let posix_home_path = Path::new("/home");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_home_path.ends_with_path(&Path::new("home"));
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn ends_with_path_missmatch_jome_home(bh: &mut BenchHarness) {
|
||||
fn ends_with_path_missmatch_jome_home(b: &mut Bencher) {
|
||||
let posix_home_path = Path::new("/home");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
posix_home_path.ends_with_path(&Path::new("jome"));
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn is_ancestor_of_path_with_10_dirs(bh: &mut BenchHarness) {
|
||||
fn is_ancestor_of_path_with_10_dirs(b: &mut Bencher) {
|
||||
let path = Path::new("/home/1/2/3/4/5/6/7/8/9");
|
||||
let mut sub = path.clone();
|
||||
sub.pop();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
path.is_ancestor_of(&sub);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn path_relative_from_forward(bh: &mut BenchHarness) {
|
||||
fn path_relative_from_forward(b: &mut Bencher) {
|
||||
let path = Path::new("/a/b/c");
|
||||
let mut other = path.clone();
|
||||
other.pop();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
path.path_relative_from(&other);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn path_relative_from_same_level(bh: &mut BenchHarness) {
|
||||
fn path_relative_from_same_level(b: &mut Bencher) {
|
||||
let path = Path::new("/a/b/c");
|
||||
let mut other = path.clone();
|
||||
other.pop();
|
||||
other.push("d");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
path.path_relative_from(&other);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn path_relative_from_backward(bh: &mut BenchHarness) {
|
||||
fn path_relative_from_backward(b: &mut Bencher) {
|
||||
let path = Path::new("/a/b");
|
||||
let mut other = path.clone();
|
||||
other.push("c");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
path.path_relative_from(&other);
|
||||
});
|
||||
}
|
||||
|
@ -117,18 +117,18 @@ pub unsafe fn exchange_free(ptr: *u8) {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn alloc_owned_small(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn alloc_owned_small(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~10
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn alloc_owned_big(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn alloc_owned_big(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~[10, ..1000]
|
||||
})
|
||||
}
|
||||
|
@ -326,15 +326,15 @@ pub fn live_allocs() -> *mut Box {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn alloc_managed_small(bh: &mut BenchHarness) {
|
||||
bh.iter(|| { @10; });
|
||||
fn alloc_managed_small(b: &mut Bencher) {
|
||||
b.iter(|| { @10; });
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn alloc_managed_big(bh: &mut BenchHarness) {
|
||||
bh.iter(|| { @([10, ..1000]); });
|
||||
fn alloc_managed_big(b: &mut Bencher) {
|
||||
b.iter(|| { @([10, ..1000]); });
|
||||
}
|
||||
}
|
||||
|
@ -4273,7 +4273,7 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use mem;
|
||||
use prelude::*;
|
||||
use ptr;
|
||||
@ -4281,12 +4281,12 @@ mod bench {
|
||||
use slice;
|
||||
|
||||
#[bench]
|
||||
fn iterator(bh: &mut BenchHarness) {
|
||||
fn iterator(b: &mut Bencher) {
|
||||
// peculiar numbers to stop LLVM from optimising the summation
|
||||
// out.
|
||||
let v = slice::from_fn(100, |i| i ^ (i << 1) ^ (i >> 1));
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut sum = 0;
|
||||
for x in v.iter() {
|
||||
sum += *x;
|
||||
@ -4297,10 +4297,10 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn mut_iterator(bh: &mut BenchHarness) {
|
||||
fn mut_iterator(b: &mut Bencher) {
|
||||
let mut v = slice::from_elem(100, 0);
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut i = 0;
|
||||
for x in v.mut_iter() {
|
||||
*x = i;
|
||||
@ -4310,109 +4310,109 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn add(bh: &mut BenchHarness) {
|
||||
fn add(b: &mut Bencher) {
|
||||
let xs: &[int] = [5, ..10];
|
||||
let ys: &[int] = [5, ..10];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
xs + ys;
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn concat(bh: &mut BenchHarness) {
|
||||
fn concat(b: &mut Bencher) {
|
||||
let xss: &[~[uint]] = slice::from_fn(100, |i| range(0, i).collect());
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let _ = xss.concat_vec();
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn connect(bh: &mut BenchHarness) {
|
||||
fn connect(b: &mut Bencher) {
|
||||
let xss: &[~[uint]] = slice::from_fn(100, |i| range(0, i).collect());
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let _ = xss.connect_vec(&0);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn push(bh: &mut BenchHarness) {
|
||||
fn push(b: &mut Bencher) {
|
||||
let mut vec: ~[uint] = ~[0u];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.push(0);
|
||||
&vec
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn starts_with_same_vector(bh: &mut BenchHarness) {
|
||||
fn starts_with_same_vector(b: &mut Bencher) {
|
||||
let vec: ~[uint] = slice::from_fn(100, |i| i);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.starts_with(vec)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn starts_with_single_element(bh: &mut BenchHarness) {
|
||||
fn starts_with_single_element(b: &mut Bencher) {
|
||||
let vec: ~[uint] = ~[0u];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.starts_with(vec)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn starts_with_diff_one_element_at_end(bh: &mut BenchHarness) {
|
||||
fn starts_with_diff_one_element_at_end(b: &mut Bencher) {
|
||||
let vec: ~[uint] = slice::from_fn(100, |i| i);
|
||||
let mut match_vec: ~[uint] = slice::from_fn(99, |i| i);
|
||||
match_vec.push(0);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.starts_with(match_vec)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn ends_with_same_vector(bh: &mut BenchHarness) {
|
||||
fn ends_with_same_vector(b: &mut Bencher) {
|
||||
let vec: ~[uint] = slice::from_fn(100, |i| i);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.ends_with(vec)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn ends_with_single_element(bh: &mut BenchHarness) {
|
||||
fn ends_with_single_element(b: &mut Bencher) {
|
||||
let vec: ~[uint] = ~[0u];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.ends_with(vec)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn ends_with_diff_one_element_at_beginning(bh: &mut BenchHarness) {
|
||||
fn ends_with_diff_one_element_at_beginning(b: &mut Bencher) {
|
||||
let vec: ~[uint] = slice::from_fn(100, |i| i);
|
||||
let mut match_vec: ~[uint] = slice::from_fn(100, |i| i);
|
||||
match_vec[0] = 200;
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.starts_with(match_vec)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn contains_last_element(bh: &mut BenchHarness) {
|
||||
fn contains_last_element(b: &mut Bencher) {
|
||||
let vec: ~[uint] = slice::from_fn(100, |i| i);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
vec.contains(&99u)
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn zero_1kb_from_elem(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn zero_1kb_from_elem(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let _v: ~[u8] = slice::from_elem(1024, 0u8);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn zero_1kb_set_memory(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn zero_1kb_set_memory(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut v: ~[u8] = slice::with_capacity(1024);
|
||||
unsafe {
|
||||
let vp = v.as_mut_ptr();
|
||||
@ -4424,17 +4424,17 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn zero_1kb_fixed_repeat(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn zero_1kb_fixed_repeat(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~[0u8, ..1024]
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn zero_1kb_loop_set(bh: &mut BenchHarness) {
|
||||
fn zero_1kb_loop_set(b: &mut Bencher) {
|
||||
// Slower because the { len, cap, [0 x T] }* repr allows a pointer to the length
|
||||
// field to be aliased (in theory) and prevents LLVM from optimizing loads away.
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v: ~[u8] = slice::with_capacity(1024);
|
||||
unsafe {
|
||||
v.set_len(1024);
|
||||
@ -4446,8 +4446,8 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn zero_1kb_mut_iter(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn zero_1kb_mut_iter(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut v: ~[u8] = slice::with_capacity(1024);
|
||||
unsafe {
|
||||
v.set_len(1024);
|
||||
@ -4460,9 +4460,9 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn random_inserts(bh: &mut BenchHarness) {
|
||||
fn random_inserts(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = slice::from_elem(30, (0u, 0u));
|
||||
for _ in range(0, 100) {
|
||||
let l = v.len();
|
||||
@ -4472,9 +4472,9 @@ mod bench {
|
||||
})
|
||||
}
|
||||
#[bench]
|
||||
fn random_removes(bh: &mut BenchHarness) {
|
||||
fn random_removes(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = slice::from_elem(130, (0u, 0u));
|
||||
for _ in range(0, 100) {
|
||||
let l = v.len();
|
||||
@ -4484,82 +4484,82 @@ mod bench {
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn sort_random_small(bh: &mut BenchHarness) {
|
||||
fn sort_random_small(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = rng.gen_vec::<u64>(5);
|
||||
v.as_mut_slice().sort();
|
||||
});
|
||||
bh.bytes = 5 * mem::size_of::<u64>() as u64;
|
||||
b.bytes = 5 * mem::size_of::<u64>() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn sort_random_medium(bh: &mut BenchHarness) {
|
||||
fn sort_random_medium(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = rng.gen_vec::<u64>(100);
|
||||
v.as_mut_slice().sort();
|
||||
});
|
||||
bh.bytes = 100 * mem::size_of::<u64>() as u64;
|
||||
b.bytes = 100 * mem::size_of::<u64>() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn sort_random_large(bh: &mut BenchHarness) {
|
||||
fn sort_random_large(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = rng.gen_vec::<u64>(10000);
|
||||
v.as_mut_slice().sort();
|
||||
});
|
||||
bh.bytes = 10000 * mem::size_of::<u64>() as u64;
|
||||
b.bytes = 10000 * mem::size_of::<u64>() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn sort_sorted(bh: &mut BenchHarness) {
|
||||
fn sort_sorted(b: &mut Bencher) {
|
||||
let mut v = slice::from_fn(10000, |i| i);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
v.sort();
|
||||
});
|
||||
bh.bytes = (v.len() * mem::size_of_val(&v[0])) as u64;
|
||||
b.bytes = (v.len() * mem::size_of_val(&v[0])) as u64;
|
||||
}
|
||||
|
||||
type BigSortable = (u64,u64,u64,u64);
|
||||
|
||||
#[bench]
|
||||
fn sort_big_random_small(bh: &mut BenchHarness) {
|
||||
fn sort_big_random_small(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = rng.gen_vec::<BigSortable>(5);
|
||||
v.sort();
|
||||
});
|
||||
bh.bytes = 5 * mem::size_of::<BigSortable>() as u64;
|
||||
b.bytes = 5 * mem::size_of::<BigSortable>() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn sort_big_random_medium(bh: &mut BenchHarness) {
|
||||
fn sort_big_random_medium(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = rng.gen_vec::<BigSortable>(100);
|
||||
v.sort();
|
||||
});
|
||||
bh.bytes = 100 * mem::size_of::<BigSortable>() as u64;
|
||||
b.bytes = 100 * mem::size_of::<BigSortable>() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn sort_big_random_large(bh: &mut BenchHarness) {
|
||||
fn sort_big_random_large(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut v = rng.gen_vec::<BigSortable>(10000);
|
||||
v.sort();
|
||||
});
|
||||
bh.bytes = 10000 * mem::size_of::<BigSortable>() as u64;
|
||||
b.bytes = 10000 * mem::size_of::<BigSortable>() as u64;
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn sort_big_sorted(bh: &mut BenchHarness) {
|
||||
fn sort_big_sorted(b: &mut Bencher) {
|
||||
let mut v = slice::from_fn(10000u, |i| (i, i, i, i));
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
v.sort();
|
||||
});
|
||||
bh.bytes = (v.len() * mem::size_of_val(&v[0])) as u64;
|
||||
b.bytes = (v.len() * mem::size_of_val(&v[0])) as u64;
|
||||
}
|
||||
}
|
||||
|
@ -4099,20 +4099,20 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
|
||||
#[bench]
|
||||
fn char_iterator(bh: &mut BenchHarness) {
|
||||
fn char_iterator(b: &mut Bencher) {
|
||||
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
||||
let len = s.char_len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.chars().len(), len));
|
||||
b.iter(|| assert_eq!(s.chars().len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn char_iterator_ascii(bh: &mut BenchHarness) {
|
||||
fn char_iterator_ascii(b: &mut Bencher) {
|
||||
let s = "Mary had a little lamb, Little lamb
|
||||
Mary had a little lamb, Little lamb
|
||||
Mary had a little lamb, Little lamb
|
||||
@ -4121,42 +4121,42 @@ mod bench {
|
||||
Mary had a little lamb, Little lamb";
|
||||
let len = s.char_len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.chars().len(), len));
|
||||
b.iter(|| assert_eq!(s.chars().len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn char_iterator_rev(bh: &mut BenchHarness) {
|
||||
fn char_iterator_rev(b: &mut Bencher) {
|
||||
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
||||
let len = s.char_len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.chars_rev().len(), len));
|
||||
b.iter(|| assert_eq!(s.chars_rev().len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn char_indicesator(bh: &mut BenchHarness) {
|
||||
fn char_indicesator(b: &mut Bencher) {
|
||||
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
||||
let len = s.char_len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.char_indices().len(), len));
|
||||
b.iter(|| assert_eq!(s.char_indices().len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn char_indicesator_rev(bh: &mut BenchHarness) {
|
||||
fn char_indicesator_rev(b: &mut Bencher) {
|
||||
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
||||
let len = s.char_len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.char_indices_rev().len(), len));
|
||||
b.iter(|| assert_eq!(s.char_indices_rev().len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn split_unicode_ascii(bh: &mut BenchHarness) {
|
||||
fn split_unicode_ascii(b: &mut Bencher) {
|
||||
let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
|
||||
|
||||
bh.iter(|| assert_eq!(s.split('V').len(), 3));
|
||||
b.iter(|| assert_eq!(s.split('V').len(), 3));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn split_unicode_not_ascii(bh: &mut BenchHarness) {
|
||||
fn split_unicode_not_ascii(b: &mut Bencher) {
|
||||
struct NotAscii(char);
|
||||
impl CharEq for NotAscii {
|
||||
fn matches(&self, c: char) -> bool {
|
||||
@ -4167,20 +4167,20 @@ mod bench {
|
||||
}
|
||||
let s = "ประเทศไทย中华Việt Namประเทศไทย中华Việt Nam";
|
||||
|
||||
bh.iter(|| assert_eq!(s.split(NotAscii('V')).len(), 3));
|
||||
b.iter(|| assert_eq!(s.split(NotAscii('V')).len(), 3));
|
||||
}
|
||||
|
||||
|
||||
#[bench]
|
||||
fn split_ascii(bh: &mut BenchHarness) {
|
||||
fn split_ascii(b: &mut Bencher) {
|
||||
let s = "Mary had a little lamb, Little lamb, little-lamb.";
|
||||
let len = s.split(' ').len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.split(' ').len(), len));
|
||||
b.iter(|| assert_eq!(s.split(' ').len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn split_not_ascii(bh: &mut BenchHarness) {
|
||||
fn split_not_ascii(b: &mut Bencher) {
|
||||
struct NotAscii(char);
|
||||
impl CharEq for NotAscii {
|
||||
#[inline]
|
||||
@ -4193,97 +4193,97 @@ mod bench {
|
||||
let s = "Mary had a little lamb, Little lamb, little-lamb.";
|
||||
let len = s.split(' ').len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.split(NotAscii(' ')).len(), len));
|
||||
b.iter(|| assert_eq!(s.split(NotAscii(' ')).len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn split_extern_fn(bh: &mut BenchHarness) {
|
||||
fn split_extern_fn(b: &mut Bencher) {
|
||||
let s = "Mary had a little lamb, Little lamb, little-lamb.";
|
||||
let len = s.split(' ').len();
|
||||
fn pred(c: char) -> bool { c == ' ' }
|
||||
|
||||
bh.iter(|| assert_eq!(s.split(pred).len(), len));
|
||||
b.iter(|| assert_eq!(s.split(pred).len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn split_closure(bh: &mut BenchHarness) {
|
||||
fn split_closure(b: &mut Bencher) {
|
||||
let s = "Mary had a little lamb, Little lamb, little-lamb.";
|
||||
let len = s.split(' ').len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.split(|c: char| c == ' ').len(), len));
|
||||
b.iter(|| assert_eq!(s.split(|c: char| c == ' ').len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn split_slice(bh: &mut BenchHarness) {
|
||||
fn split_slice(b: &mut Bencher) {
|
||||
let s = "Mary had a little lamb, Little lamb, little-lamb.";
|
||||
let len = s.split(' ').len();
|
||||
|
||||
bh.iter(|| assert_eq!(s.split(&[' ']).len(), len));
|
||||
b.iter(|| assert_eq!(s.split(&[' ']).len(), len));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn is_utf8_100_ascii(bh: &mut BenchHarness) {
|
||||
fn is_utf8_100_ascii(b: &mut Bencher) {
|
||||
|
||||
let s = bytes!("Hello there, the quick brown fox jumped over the lazy dog! \
|
||||
Lorem ipsum dolor sit amet, consectetur. ");
|
||||
|
||||
assert_eq!(100, s.len());
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
is_utf8(s)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn is_utf8_100_multibyte(bh: &mut BenchHarness) {
|
||||
fn is_utf8_100_multibyte(b: &mut Bencher) {
|
||||
let s = bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
|
||||
assert_eq!(100, s.len());
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
is_utf8(s)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn from_utf8_lossy_100_ascii(bh: &mut BenchHarness) {
|
||||
fn from_utf8_lossy_100_ascii(b: &mut Bencher) {
|
||||
let s = bytes!("Hello there, the quick brown fox jumped over the lazy dog! \
|
||||
Lorem ipsum dolor sit amet, consectetur. ");
|
||||
|
||||
assert_eq!(100, s.len());
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let _ = from_utf8_lossy(s);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn from_utf8_lossy_100_multibyte(bh: &mut BenchHarness) {
|
||||
fn from_utf8_lossy_100_multibyte(b: &mut Bencher) {
|
||||
let s = bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
|
||||
assert_eq!(100, s.len());
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let _ = from_utf8_lossy(s);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn from_utf8_lossy_invalid(bh: &mut BenchHarness) {
|
||||
fn from_utf8_lossy_invalid(b: &mut Bencher) {
|
||||
let s = bytes!("Hello", 0xC0, 0x80, " There", 0xE6, 0x83, " Goodbye");
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let _ = from_utf8_lossy(s);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn from_utf8_lossy_100_invalid(bh: &mut BenchHarness) {
|
||||
fn from_utf8_lossy_100_invalid(b: &mut Bencher) {
|
||||
let s = ::slice::from_elem(100, 0xF5u8);
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let _ = from_utf8_lossy(s);
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_connect(bh: &mut BenchHarness) {
|
||||
fn bench_connect(b: &mut Bencher) {
|
||||
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
||||
let sep = "→";
|
||||
let v = [s, s, s, s, s, s, s, s, s, s];
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
assert_eq!(v.connect(sep).len(), s.len() * 10 + sep.len() * 9);
|
||||
})
|
||||
}
|
||||
|
@ -289,21 +289,21 @@ impl<H:Writer> ::hash::Hash<H> for StrBuf {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use str::{Str, StrSlice};
|
||||
use super::StrBuf;
|
||||
|
||||
#[bench]
|
||||
fn bench_with_capacity(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
fn bench_with_capacity(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
StrBuf::with_capacity(100)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_push_str(bh: &mut BenchHarness) {
|
||||
fn bench_push_str(b: &mut Bencher) {
|
||||
let s = "ศไทย中华Việt Nam; Mary had a little lamb, Little lamb";
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
let mut r = StrBuf::new();
|
||||
r.push_str(s);
|
||||
});
|
||||
|
@ -11,7 +11,7 @@
|
||||
//! Support code for rustc's built in unit-test and micro-benchmarking
|
||||
//! framework.
|
||||
//!
|
||||
//! Almost all user code will only be interested in `BenchHarness` and
|
||||
//! Almost all user code will only be interested in `Bencher` and
|
||||
//! `black_box`. All other interactions (such as writing tests and
|
||||
//! benchmarks themselves) should be done via the `#[test]` and
|
||||
//! `#[bench]` attributes.
|
||||
@ -64,7 +64,7 @@ use std::task;
|
||||
|
||||
// to be used by rustc to compile tests in libtest
|
||||
pub mod test {
|
||||
pub use {BenchHarness, TestName, TestResult, TestDesc,
|
||||
pub use {Bencher, TestName, TestResult, TestDesc,
|
||||
TestDescAndFn, TestOpts, TrFailed, TrIgnored, TrOk,
|
||||
Metric, MetricMap, MetricAdded, MetricRemoved,
|
||||
MetricChange, Improvement, Regression, LikelyNoise,
|
||||
@ -119,7 +119,7 @@ impl TestDesc {
|
||||
|
||||
/// Represents a benchmark function.
|
||||
pub trait TDynBenchFn {
|
||||
fn run(&self, harness: &mut BenchHarness);
|
||||
fn run(&self, harness: &mut Bencher);
|
||||
}
|
||||
|
||||
// A function that runs a test. If the function returns successfully,
|
||||
@ -128,7 +128,7 @@ pub trait TDynBenchFn {
|
||||
// to support isolation of tests into tasks.
|
||||
pub enum TestFn {
|
||||
StaticTestFn(fn()),
|
||||
StaticBenchFn(fn(&mut BenchHarness)),
|
||||
StaticBenchFn(fn(&mut Bencher)),
|
||||
StaticMetricFn(proc(&mut MetricMap)),
|
||||
DynTestFn(proc():Send),
|
||||
DynMetricFn(proc(&mut MetricMap)),
|
||||
@ -153,7 +153,7 @@ impl TestFn {
|
||||
/// This is feed into functions marked with `#[bench]` to allow for
|
||||
/// set-up & tear-down before running a piece of code repeatedly via a
|
||||
/// call to `iter`.
|
||||
pub struct BenchHarness {
|
||||
pub struct Bencher {
|
||||
iterations: u64,
|
||||
ns_start: u64,
|
||||
ns_end: u64,
|
||||
@ -300,7 +300,7 @@ Test Attributes:
|
||||
#[test] - Indicates a function is a test to be run. This function
|
||||
takes no arguments.
|
||||
#[bench] - Indicates a function is a benchmark to be run. This
|
||||
function takes one argument (test::BenchHarness).
|
||||
function takes one argument (test::Bencher).
|
||||
#[should_fail] - This function (also labeled with #[test]) will only pass if
|
||||
the code causes a failure (an assertion failure or fail!)
|
||||
#[ignore] - When applied to a function which is already attributed as a
|
||||
@ -1178,7 +1178,7 @@ pub fn black_box<T>(dummy: T) {
|
||||
}
|
||||
|
||||
|
||||
impl BenchHarness {
|
||||
impl Bencher {
|
||||
/// Callback for benchmark functions to run in their body.
|
||||
pub fn iter<T>(&mut self, inner: || -> T) {
|
||||
self.ns_start = precise_time_ns();
|
||||
@ -1205,13 +1205,13 @@ impl BenchHarness {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bench_n(&mut self, n: u64, f: |&mut BenchHarness|) {
|
||||
pub fn bench_n(&mut self, n: u64, f: |&mut Bencher|) {
|
||||
self.iterations = n;
|
||||
f(self);
|
||||
}
|
||||
|
||||
// This is a more statistics-driven benchmark algorithm
|
||||
pub fn auto_bench(&mut self, f: |&mut BenchHarness|) -> stats::Summary {
|
||||
pub fn auto_bench(&mut self, f: |&mut Bencher|) -> stats::Summary {
|
||||
|
||||
// Initial bench run to get ballpark figure.
|
||||
let mut n = 1_u64;
|
||||
@ -1276,10 +1276,10 @@ impl BenchHarness {
|
||||
|
||||
pub mod bench {
|
||||
use std::cmp;
|
||||
use super::{BenchHarness, BenchSamples};
|
||||
use super::{Bencher, BenchSamples};
|
||||
|
||||
pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
|
||||
let mut bs = BenchHarness {
|
||||
pub fn benchmark(f: |&mut Bencher|) -> BenchSamples {
|
||||
let mut bs = Bencher {
|
||||
iterations: 0,
|
||||
ns_start: 0,
|
||||
ns_end: 0,
|
||||
|
@ -1036,21 +1036,21 @@ mod tests {
|
||||
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
use BenchHarness;
|
||||
use Bencher;
|
||||
use stats::Stats;
|
||||
|
||||
#[bench]
|
||||
pub fn sum_three_items(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
pub fn sum_three_items(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
[1e20, 1.5, -1e20].sum();
|
||||
})
|
||||
}
|
||||
#[bench]
|
||||
pub fn sum_many_f64(bh: &mut BenchHarness) {
|
||||
pub fn sum_many_f64(b: &mut Bencher) {
|
||||
let nums = [-1e30, 1e60, 1e30, 1.0, -1e60];
|
||||
let v = Vec::from_fn(500, |i| nums[i%5]);
|
||||
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
v.as_slice().sum();
|
||||
})
|
||||
}
|
||||
|
@ -818,28 +818,28 @@ mod test {
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use self::test::Bencher;
|
||||
use super::Uuid;
|
||||
|
||||
#[bench]
|
||||
pub fn create_uuids(bh: &mut BenchHarness) {
|
||||
bh.iter(|| {
|
||||
pub fn create_uuids(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
Uuid::new_v4();
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn uuid_to_str(bh: &mut BenchHarness) {
|
||||
pub fn uuid_to_str(b: &mut Bencher) {
|
||||
let u = Uuid::new_v4();
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
u.to_str();
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn parse_str(bh: &mut BenchHarness) {
|
||||
pub fn parse_str(b: &mut Bencher) {
|
||||
let s = "urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4";
|
||||
bh.iter(|| {
|
||||
b.iter(|| {
|
||||
Uuid::parse_string(s).unwrap();
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user