Skip to content

Commit 6f198a6

Browse files
committed
feat!: add warmup runs
1 parent 9c6a5a8 commit 6f198a6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

crates/bencher_compat/src/compat.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use codspeed::codspeed::{black_box, CodSpeed};
1+
use codspeed::codspeed::{black_box, CodSpeed, WARMUP_RUNS};
22

33
pub struct Bencher {
44
pub bytes: u64,
@@ -24,6 +24,9 @@ impl Bencher {
2424
F: FnMut() -> T,
2525
{
2626
let uri = self.current_uri.as_str();
27+
for _ in 0..WARMUP_RUNS {
28+
black_box(inner());
29+
}
2730
self.codspeed.start_benchmark(uri);
2831
black_box(inner());
2932
self.codspeed.end_benchmark();

crates/codspeed/src/codspeed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use colored::Colorize;
44

55
use crate::measurement;
66

7+
pub const WARMUP_RUNS: u32 = 5;
8+
79
//TODO: use std::hint::black_box when it's stable
810
pub fn black_box<T>(dummy: T) -> T {
911
unsafe {

crates/criterion_compat/src/compat/bencher.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ impl Bencher {
2020
R: FnMut() -> O,
2121
{
2222
let mut codspeed = self.codspeed.borrow_mut();
23+
for _ in 0..codspeed::codspeed::WARMUP_RUNS {
24+
black_box(routine());
25+
}
2326
codspeed.start_benchmark(self.uri.as_str());
2427
black_box(routine());
2528
codspeed.end_benchmark();
@@ -44,6 +47,11 @@ impl Bencher {
4447
R: FnMut(I) -> O,
4548
{
4649
let mut codspeed = self.codspeed.borrow_mut();
50+
for _ in 0..codspeed::codspeed::WARMUP_RUNS {
51+
let input = black_box(setup());
52+
let output = routine(input);
53+
drop(black_box(output));
54+
}
4755
let input = black_box(setup());
4856
codspeed.start_benchmark(self.uri.as_str());
4957
let output = routine(input);
@@ -82,8 +90,15 @@ impl Bencher {
8290
R: FnMut(&mut I) -> O,
8391
{
8492
let mut codspeed = self.codspeed.borrow_mut();
85-
let mut input = black_box(setup());
8693

94+
for _ in 0..codspeed::codspeed::WARMUP_RUNS {
95+
let mut input = black_box(setup());
96+
let output = routine(&mut input);
97+
drop(black_box(output));
98+
drop(black_box(input));
99+
}
100+
101+
let mut input = black_box(setup());
87102
codspeed.start_benchmark(self.uri.as_str());
88103
let output = routine(&mut input);
89104
codspeed.end_benchmark();

0 commit comments

Comments
 (0)