diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2014-12-07 12:17:33 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2014-12-13 17:03:47 -0500 |
| commit | 879ebce6a4023632cfd448749997ce3e4e24b05d (patch) | |
| tree | 5ea38f68d4b2dcf2bf75c826271f935d87727df1 | |
| parent | 9b075bcf3ffef3f11d8401b55feaa02c1e6553d2 (diff) | |
| download | rust-879ebce6a4023632cfd448749997ce3e4e24b05d.tar.gz rust-879ebce6a4023632cfd448749997ce3e4e24b05d.zip | |
libcollections: use unboxed closures
| -rw-r--r-- | src/libcollections/bench.rs | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/libcollections/bench.rs b/src/libcollections/bench.rs index a212f22f899..3346e55158a 100644 --- a/src/libcollections/bench.rs +++ b/src/libcollections/bench.rs @@ -13,9 +13,14 @@ use std::rand; use std::rand::Rng; use test::Bencher; -pub fn insert_rand_n<M>(n: uint, map: &mut M, b: &mut Bencher, - insert: |&mut M, uint|, - remove: |&mut M, uint|) { +pub fn insert_rand_n<M, I, R>(n: uint, + map: &mut M, + b: &mut Bencher, + mut insert: I, + mut remove: R) where + I: FnMut(&mut M, uint), + R: FnMut(&mut M, uint), +{ // setup let mut rng = rand::weak_rng(); @@ -31,9 +36,14 @@ pub fn insert_rand_n<M>(n: uint, map: &mut M, b: &mut Bencher, }) } -pub fn insert_seq_n<M>(n: uint, map: &mut M, b: &mut Bencher, - insert: |&mut M, uint|, - remove: |&mut M, uint|) { +pub fn insert_seq_n<M, I, R>(n: uint, + map: &mut M, + b: &mut Bencher, + mut insert: I, + mut remove: R) where + I: FnMut(&mut M, uint), + R: FnMut(&mut M, uint), +{ // setup for i in range(0u, n) { insert(map, i * 2); @@ -48,9 +58,14 @@ pub fn insert_seq_n<M>(n: uint, map: &mut M, b: &mut Bencher, }) } -pub fn find_rand_n<M, T>(n: uint, map: &mut M, b: &mut Bencher, - insert: |&mut M, uint|, - find: |&M, uint| -> T) { +pub fn find_rand_n<M, T, I, F>(n: uint, + map: &mut M, + b: &mut Bencher, + mut insert: I, + mut find: F) where + I: FnMut(&mut M, uint), + F: FnMut(&M, uint) -> T, +{ // setup let mut rng = rand::weak_rng(); let mut keys = Vec::from_fn(n, |_| rng.gen::<uint>() % n); @@ -70,9 +85,14 @@ pub fn find_rand_n<M, T>(n: uint, map: &mut M, b: &mut Bencher, }) } -pub fn find_seq_n<M, T>(n: uint, map: &mut M, b: &mut Bencher, - insert: |&mut M, uint|, - find: |&M, uint| -> T) { +pub fn find_seq_n<M, T, I, F>(n: uint, + map: &mut M, + b: &mut Bencher, + mut insert: I, + mut find: F) where + I: FnMut(&mut M, uint), + F: FnMut(&M, uint) -> T, +{ // setup for i in range(0u, n) { insert(map, i); |
