Skip to content

Commit f703a54

Browse files
committed
chore: add sleep benchmarks
1 parent 9db060d commit f703a54

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

crates/criterion_compat/benches/criterion_integration/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod iter_with_large_setup;
66
pub mod iter_with_setup;
77
pub mod measurement_overhead;
88
pub mod sampling_mode;
9+
pub mod sleep;
910
pub mod special_characters;
1011
pub mod with_inputs;
1112

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use codspeed_criterion_compat::{criterion_group, Criterion};
2+
use std::time::Duration;
3+
4+
fn sleep_benchmarks(c: &mut Criterion) {
5+
c.bench_function("sleep_1ms", |b| {
6+
b.iter(|| std::thread::sleep(Duration::from_millis(1)))
7+
});
8+
9+
c.bench_function("sleep_10ms", |b| {
10+
b.iter(|| std::thread::sleep(Duration::from_millis(10)))
11+
});
12+
13+
c.bench_function("sleep_50ms", |b| {
14+
b.iter(|| std::thread::sleep(Duration::from_millis(50)))
15+
});
16+
17+
c.bench_function("sleep_100ms", |b| {
18+
b.iter(|| std::thread::sleep(Duration::from_millis(100)))
19+
});
20+
}
21+
22+
criterion_group!(benches, sleep_benchmarks);

crates/criterion_compat/benches/criterion_integration_main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ criterion_main! {
1313
criterion_integration::measurement_overhead::benches,
1414
criterion_integration::custom_measurement::benches,
1515
criterion_integration::sampling_mode::benches,
16+
criterion_integration::sleep::benches,
1617
criterion_integration::async_measurement_overhead::benches,
1718
}

crates/divan_compat/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ codspeed-divan-compat-macros = { version = "=2.10.1", path = './macros' }
2525
[[bench]]
2626
name = "basic_example"
2727
harness = false
28+
29+
[[bench]]
30+
name = "sleep_benches"
31+
harness = false
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#[divan::bench]
2+
fn sleep_1ms() {
3+
std::thread::sleep(std::time::Duration::from_millis(1));
4+
}
5+
6+
#[divan::bench]
7+
fn sleep_10ms() {
8+
std::thread::sleep(std::time::Duration::from_millis(10));
9+
}
10+
11+
#[divan::bench]
12+
fn sleep_50ms() {
13+
std::thread::sleep(std::time::Duration::from_millis(50));
14+
}
15+
16+
#[divan::bench]
17+
fn sleep_100ms() {
18+
std::thread::sleep(std::time::Duration::from_millis(100));
19+
}
20+
21+
// Tests COD-1044, do not modify the sample size or count!
22+
#[divan::bench(sample_size = 3, sample_count = 6)]
23+
fn sleep_100ms_with_custom_sample() {
24+
std::thread::sleep(std::time::Duration::from_millis(100));
25+
}
26+
27+
fn main() {
28+
codspeed_divan_compat::main();
29+
}

0 commit comments

Comments
 (0)