Change:
the closure being passed into in BTreeMap and VecMap's benches has a trailing semi-colon making the return value , and thus making the entire operation a no-op. Removing the semi-colon causes lifetime conflict issues. CC
I have a branch that just gives up and replaces these with macros. This results in clearer and more concise code like . Confirmed produces sane results in benchmark output. Hope to submit something tomorrow.

Discussion:
// option. This file may not be copied, modified, or distributed // except according to those terms. <del> use prelude::*; use std::rand; use std::rand::Rng; use test::{Bencher, black_box}; pub fn insert_rand_n<M, I, R>(n: usize, map: &mut M, b: &mut Bencher, mut insert: I, mut remove: R) where I: FnMut(&mut M, usize), R: FnMut(&mut M, usize), { // setup let mut rng = rand::weak_rng(); for _ in 0..n { insert(map, rng.gen::<usize>() % n); } // measure b.iter(|| { let k = rng.gen::<usize>() % n; insert(map, k); remove(map, k); }); black_box(map); </del> <ins> macro_rules! map_insert_rand_bench { ($name: ident, $n: expr, $map: ident) => ( #[bench] pub fn $name(b: &mut ::test::Bencher) { use std::rand; use std::rand::Rng; use test::black_box; let n: usize = $n; let mut map = $map::new(); // setup let mut rng = rand::weak_rng(); for _ in 0..n { let i = rng.gen() % n; map.insert(i, i); } // measure b.iter(|| { let k = rng.gen() % n; map.insert(k, k); map.remove(&k); }); black_box(map); } ) </ins> } <del> pub fn insert_seq_n<M, I, R>(n: usize, map: &mut M, b: &mut Bencher, mut insert: I, mut remove: R) where I: FnMut(&mut M, usize), R: FnMut(&mut M, usize), { // setup for i in 0..n { insert(map, i * 2); } // measure let mut i = 1; b.iter(|| { insert(map, i); remove(map, i); i = (i + 2) % n; }); black_box(map); </del> <ins> macro_rules! map_insert_seq_bench { ($name: ident, $n: expr, $map: ident) => ( #[bench] pub fn $name(b: &mut ::test::Bencher) { use test::black_box; let mut map = $map::new(); let n: usize = $n; // setup for i in 0..n { map.insert(i * 2, i * 2); } // measure let mut i = 1; b.iter(|| { map.insert(i, i); map.remove(&i); i = (i + 2) % n; }); black_box(map); } ) </ins> } <del> pub fn find_rand_n<M, T, I, F>(n: usize, map: &mut M, b: &mut Bencher, mut insert: I, mut find: F) where I: FnMut(&mut M, usize), F: FnMut(&M, usize) -> T, { // setup let mut rng = rand::weak_rng(); let mut keys: Vec<_> = (0..n).map(|_| rng.gen::<usize>() % n).collect(); for k in &keys { insert(map, *k); } rng.shuffle(&mut keys); // measure let mut i = 0; b.iter(|| { let t = find(map, keys[i]); i = (i + 1) % n; black_box(t); }) </del> <ins> macro_rules! map_find_rand_bench { ($name: ident, $n: expr, $map: ident) => ( #[bench] pub fn $name(b: &mut ::test::Bencher) { use std::rand; use std::rand::Rng; use test::black_box; let mut map = $map::new(); let n: usize = $n; // setup let mut rng = rand::weak_rng(); let mut keys: Vec<_> = (0..n).map(|_| rng.gen() % n).collect(); for &k in &keys { map.insert(k, k); } rng.shuffle(&mut keys); // measure let mut i = 0; b.iter(|| { let t = map.get(&keys[i]); i = (i + 1) % n; black_box(t); }) } ) </ins> } <del> pub fn find_seq_n<M, T, I, F>(n: usize, map: &mut M, b: &mut Bencher, mut insert: I, mut find: F) where I: FnMut(&mut M, usize), F: FnMut(&M, usize) -> T, { // setup for i in 0..n { insert(map, i); } // measure let mut i = 0; b.iter(|| { let x = find(map, i); i = (i + 1) % n; black_box(x); }) </del> <ins> macro_rules! map_find_seq_bench { ($name: ident, $n: expr, $map: ident) => ( #[bench] pub fn $name(b: &mut ::test::Bencher) { use test::black_box; let mut map = $map::new(); let n: usize = $n; // setup for i in 0..n { map.insert(i, i); } // measure let mut i = 0; b.iter(|| { let x = map.get(&i); i = (i + 1) % n; black_box(x); }) } ) </ins> }

use test::{Bencher, black_box}; use super::BTreeMap; <del> use bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n}; #[bench] pub fn insert_rand_100(b: &mut Bencher) { let mut m = BTreeMap::new(); insert_rand_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } #[bench] pub fn insert_rand_10_000(b: &mut Bencher) { let mut m = BTreeMap::new(); insert_rand_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } // Insert seq #[bench] pub fn insert_seq_100(b: &mut Bencher) { let mut m = BTreeMap::new(); insert_seq_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } #[bench] pub fn insert_seq_10_000(b: &mut Bencher) { let mut m = BTreeMap::new(); insert_seq_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } </del> <ins> map_insert_rand_bench!{insert_rand_100,    100,    BTreeMap} map_insert_rand_bench!{insert_rand_10_000, 10_000, BTreeMap} </ins> <del> // Find rand #[bench] pub fn find_rand_100(b: &mut Bencher) { let mut m = BTreeMap::new(); find_rand_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } #[bench] pub fn find_rand_10_000(b: &mut Bencher) { let mut m = BTreeMap::new(); find_rand_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } </del> <ins> map_insert_seq_bench!{insert_seq_100,    100,    BTreeMap} map_insert_seq_bench!{insert_seq_10_000, 10_000, BTreeMap} </ins> <del> // Find seq #[bench] pub fn find_seq_100(b: &mut Bencher) { let mut m = BTreeMap::new(); find_seq_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } </del> <ins> map_find_rand_bench!{find_rand_100,    100,    BTreeMap} map_find_rand_bench!{find_rand_10_000, 10_000, BTreeMap} </ins> <del> #[bench] pub fn find_seq_10_000(b: &mut Bencher) { let mut m = BTreeMap::new(); find_seq_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } </del> <ins> map_find_seq_bench!{find_seq_100,    100,    BTreeMap} map_find_seq_bench!{find_seq_10_000, 10_000, BTreeMap} </ins> fn bench_iter(b: &mut Bencher, size: i32) { let mut map = BTreeMap::<i32, i32>::new();

} <del> #[cfg(test)] mod bench; </del> <ins> #[cfg(test)] #[macro_use] mod bench; </ins> // FIXME(#14344) this shouldn't be necessary #[doc(hidden)]

#[cfg(test)] mod bench { <del> use test::Bencher; </del> use super::VecMap; <del> use bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n}; #[bench] pub fn insert_rand_100(b: &mut Bencher) { let mut m = VecMap::new(); insert_rand_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } #[bench] pub fn insert_rand_10_000(b: &mut Bencher) { let mut m = VecMap::new(); insert_rand_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } // Insert seq #[bench] pub fn insert_seq_100(b: &mut Bencher) { let mut m = VecMap::new(); insert_seq_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } #[bench] pub fn insert_seq_10_000(b: &mut Bencher) { let mut m = VecMap::new(); insert_seq_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.remove(&i); }); } </del> <ins> map_insert_rand_bench!{insert_rand_100,    100,    VecMap} map_insert_rand_bench!{insert_rand_10_000, 10_000, VecMap} </ins> <del> // Find rand #[bench] pub fn find_rand_100(b: &mut Bencher) { let mut m = VecMap::new(); find_rand_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } #[bench] pub fn find_rand_10_000(b: &mut Bencher) { let mut m = VecMap::new(); find_rand_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } </del> <ins> map_insert_seq_bench!{insert_seq_100,    100,    VecMap} map_insert_seq_bench!{insert_seq_10_000, 10_000, VecMap} </ins> <del> // Find seq #[bench] pub fn find_seq_100(b: &mut Bencher) { let mut m = VecMap::new(); find_seq_n(100, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } </del> <ins> map_find_rand_bench!{find_rand_100,    100,    VecMap} map_find_rand_bench!{find_rand_10_000, 10_000, VecMap} </ins> <del> #[bench] pub fn find_seq_10_000(b: &mut Bencher) { let mut m = VecMap::new(); find_seq_n(10_000, &mut m, b, |m, i| { m.insert(i, 1); }, |m, i| { m.get(&i); }); } </del> <ins> map_find_seq_bench!{find_seq_100,    100,    VecMap} map_find_seq_bench!{find_seq_10_000, 10_000, VecMap} </ins> }