about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStjepan Glavina <stjepang@gmail.com>2017-02-04 18:04:26 +0100
committerStjepan Glavina <stjepang@gmail.com>2017-02-04 18:04:26 +0100
commitfa457bff264ea62acf56bb9e645b8227ecdc7529 (patch)
tree0136bc2c1774372f40ea6cd2fb426ebe85180035
parenta884a6c60d3ec2338d7dfed9998a7aa96e10260e (diff)
downloadrust-fa457bff264ea62acf56bb9e645b8227ecdc7529.tar.gz
rust-fa457bff264ea62acf56bb9e645b8227ecdc7529.zip
Minor fix in the *_expensive benchmark
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`.
-rw-r--r--src/libcollectionstest/slice.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs
index 1b52214dee6..b9dec6be7b8 100644
--- a/src/libcollectionstest/slice.rs
+++ b/src/libcollectionstest/slice.rs
@@ -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;