Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map search benches are incorrect #22134

Closed
Gankra opened this issue Feb 10, 2015 · 1 comment
Closed

Map search benches are incorrect #22134

Gankra opened this issue Feb 10, 2015 · 1 comment

Comments

@Gankra
Copy link
Contributor

Gankra commented Feb 10, 2015

the find closure being passed into collections::bench::find_*_n in BTreeMap and VecMap's benches has a trailing semi-colon making the return value (), and thus making the entire operation a no-op.

    #[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); });
                                     ^~~~~ big trouble in little BTreeMap town
    }

Removing the semi-colon causes lifetime conflict issues.

map.rs:1882:32: 1882:39 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
map.rs:1882                     |m, i| { m.get(&i) });
                                           ^~~~~~~
map.rs:1880:9: 1880:20 note: first, the lifetime cannot outlive the expression at 1880:8...
map.rs:1880         find_rand_n(100, &mut m, b,
                    ^~~~~~~~~~~
map.rs:1880:9: 1880:20 note: ...so that the declared lifetime parameter bounds are satisfied
map.rs:1880         find_rand_n(100, &mut m, b,
                    ^~~~~~~~~~~
map.rs:1882:30: 1882:31 note: but, the lifetime must be valid for the expression at 1882:29...
map.rs:1882                     |m, i| { m.get(&i) });
                                         ^
map.rs:1882:30: 1882:31 note: ...so that auto-reference is valid at the time of borrow
map.rs:1882                     |m, i| { m.get(&i) });

CC @alexcrichton

@Gankra
Copy link
Contributor Author

Gankra commented Feb 10, 2015

I have a branch that just gives up and replaces these with macros. This results in clearer and more concise code like map_insert_rand_bench!{insert_rand_100, 100, BTreeMap}.

Confirmed produces sane results in benchmark output. Hope to submit something tomorrow.

@Gankra Gankra closed this as completed in b24c6fd Feb 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant