From 46a8beb4b2536740b632d01abff8d341bbf20b6d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 01:22:19 +0100 Subject: [PATCH] Move some bench tests back from libtest --- src/libtest/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 3fcba0f579145..cb0ce480e4273 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -44,3 +44,28 @@ pub fn black_box(dummy: T) -> T { pub fn black_box(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::>(); + b.iter(|| { + v.sum(); + }) + } + + #[bench] + pub fn no_iter(_: &mut Bencher) {} +}