Skip to content

Commit

Permalink
feat!: add warmup runs
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Jul 4, 2023
1 parent 9c6a5a8 commit 6f198a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion crates/bencher_compat/src/compat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use codspeed::codspeed::{black_box, CodSpeed};
use codspeed::codspeed::{black_box, CodSpeed, WARMUP_RUNS};

pub struct Bencher {
pub bytes: u64,
Expand All @@ -24,6 +24,9 @@ impl Bencher {
F: FnMut() -> T,
{
let uri = self.current_uri.as_str();
for _ in 0..WARMUP_RUNS {
black_box(inner());
}
self.codspeed.start_benchmark(uri);
black_box(inner());
self.codspeed.end_benchmark();
Expand Down
2 changes: 2 additions & 0 deletions crates/codspeed/src/codspeed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use colored::Colorize;

use crate::measurement;

pub const WARMUP_RUNS: u32 = 5;

//TODO: use std::hint::black_box when it's stable
pub fn black_box<T>(dummy: T) -> T {
unsafe {
Expand Down
17 changes: 16 additions & 1 deletion crates/criterion_compat/src/compat/bencher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ impl Bencher {
R: FnMut() -> O,
{
let mut codspeed = self.codspeed.borrow_mut();
for _ in 0..codspeed::codspeed::WARMUP_RUNS {
black_box(routine());
}
codspeed.start_benchmark(self.uri.as_str());
black_box(routine());
codspeed.end_benchmark();
Expand All @@ -44,6 +47,11 @@ impl Bencher {
R: FnMut(I) -> O,
{
let mut codspeed = self.codspeed.borrow_mut();
for _ in 0..codspeed::codspeed::WARMUP_RUNS {
let input = black_box(setup());
let output = routine(input);
drop(black_box(output));
}
let input = black_box(setup());
codspeed.start_benchmark(self.uri.as_str());
let output = routine(input);
Expand Down Expand Up @@ -82,8 +90,15 @@ impl Bencher {
R: FnMut(&mut I) -> O,
{
let mut codspeed = self.codspeed.borrow_mut();
let mut input = black_box(setup());

for _ in 0..codspeed::codspeed::WARMUP_RUNS {
let mut input = black_box(setup());
let output = routine(&mut input);
drop(black_box(output));
drop(black_box(input));
}

let mut input = black_box(setup());
codspeed.start_benchmark(self.uri.as_str());
let output = routine(&mut input);
codspeed.end_benchmark();
Expand Down

0 comments on commit 6f198a6

Please sign in to comment.