Skip to content

Commit

Permalink
Minor fix in the *_expensive benchmark
Browse files Browse the repository at this point in the history
Before, the `count` would be copied into the closure and could
potentially be optimized way. This change ensures it's borrowed by
closure and finally consumed by `test::black_box`.
  • Loading branch information
Stjepan Glavina committed Feb 4, 2017
1 parent a884a6c commit fa457bf
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/libcollectionstest/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,18 +1429,15 @@ mod bench {
fn sort_large_random_expensive(b: &mut Bencher) {
let len = 10000;
b.iter(|| {
let mut v = gen_random(len);
let mut count = 0;
let cmp = move |a: &u64, b: &u64| {
v.sort_by(|a: &u64, b: &u64| {
count += 1;
if count % 1_000_000_000 == 0 {
panic!("should not happen");
}
(*a as f64).cos().partial_cmp(&(*b as f64).cos()).unwrap()
};

let mut v = gen_random(len);
v.sort_by(cmp);

});
black_box(count);
});
b.bytes = len as u64 * mem::size_of::<u64>() as u64;
Expand Down

0 comments on commit fa457bf

Please sign in to comment.