Skip to content

Commit 8a36f76

Browse files
authored
Rollup merge of rust-lang#59304 - gnzlbg:bench_tests, r=alexcrichton
Move some bench tests back from libtest It doesn't make much sense to test these on rust-lang/libtest since they exercise the `#[bench]` macro which is part of rust-lang/rust. This PR moves these tests back here. r? @alexcrichton
2 parents 0407c64 + 46a8beb commit 8a36f76

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/libtest/lib.rs

+25
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,28 @@ pub fn black_box<T>(dummy: T) -> T {
4444
pub fn black_box<T>(dummy: T) -> T {
4545
dummy
4646
}
47+
48+
#[cfg(test)]
49+
mod tests {
50+
use crate::Bencher;
51+
use libtest::stats::Stats;
52+
53+
#[bench]
54+
pub fn sum_three_items(b: &mut Bencher) {
55+
b.iter(|| {
56+
[1e20f64, 1.5f64, -1e20f64].sum();
57+
})
58+
}
59+
60+
#[bench]
61+
pub fn sum_many_f64(b: &mut Bencher) {
62+
let nums = [-1e30f64, 1e60, 1e30, 1.0, -1e60];
63+
let v = (0..500).map(|i| nums[i % 5]).collect::<Vec<_>>();
64+
b.iter(|| {
65+
v.sum();
66+
})
67+
}
68+
69+
#[bench]
70+
pub fn no_iter(_: &mut Bencher) {}
71+
}

0 commit comments

Comments
 (0)