Skip to content

Move some bench tests back from libtest #59304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}