diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-03-22 19:31:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-22 19:31:30 +0100 |
| commit | 8a36f7673571c61b81c2e04698a743418faeb447 (patch) | |
| tree | 5df73e4c9ab5e4f6296c9525a6cc701e84e95e25 | |
| parent | 0407c642f528d2b3618ef1c671f3b988d51c858a (diff) | |
| parent | 46a8beb4b2536740b632d01abff8d341bbf20b6d (diff) | |
| download | rust-8a36f7673571c61b81c2e04698a743418faeb447.tar.gz rust-8a36f7673571c61b81c2e04698a743418faeb447.zip | |
Rollup merge of #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
| -rw-r--r-- | src/libtest/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 3fcba0f5791..cb0ce480e42 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -44,3 +44,28 @@ pub fn black_box<T>(dummy: T) -> T { pub fn black_box<T>(dummy: T) -> T { dummy } + +#[cfg(test)] +mod tests { + use crate::Bencher; + use libtest::stats::Stats; + + #[bench] + pub fn sum_three_items(b: &mut Bencher) { + b.iter(|| { + [1e20f64, 1.5f64, -1e20f64].sum(); + }) + } + + #[bench] + pub fn sum_many_f64(b: &mut Bencher) { + let nums = [-1e30f64, 1e60, 1e30, 1.0, -1e60]; + let v = (0..500).map(|i| nums[i % 5]).collect::<Vec<_>>(); + b.iter(|| { + v.sum(); + }) + } + + #[bench] + pub fn no_iter(_: &mut Bencher) {} +} |
