From b166c4d7c975b4a2be32adb2014595ea4f5ca76c Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Wed, 12 Mar 2025 10:33:48 +0100 Subject: [PATCH] feat: add time scale measurement benches --- crates/divan_compat/examples/Cargo.toml | 4 +++ .../examples/benches/time_scale.rs | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 crates/divan_compat/examples/benches/time_scale.rs diff --git a/crates/divan_compat/examples/Cargo.toml b/crates/divan_compat/examples/Cargo.toml index 67de38e0..30f830ca 100644 --- a/crates/divan_compat/examples/Cargo.toml +++ b/crates/divan_compat/examples/Cargo.toml @@ -29,6 +29,10 @@ harness = false name = "time" harness = false +[[bench]] +name = "time_scale" +harness = false + [[bench]] name = "the_algorithms" harness = false diff --git a/crates/divan_compat/examples/benches/time_scale.rs b/crates/divan_compat/examples/benches/time_scale.rs new file mode 100644 index 00000000..c4c8baa7 --- /dev/null +++ b/crates/divan_compat/examples/benches/time_scale.rs @@ -0,0 +1,28 @@ +fn main() { + divan::main(); +} + +#[divan::bench] +fn sleep_1ns() { + std::thread::sleep(std::time::Duration::from_nanos(1)); +} + +#[divan::bench] +fn sleep_100ns() { + std::thread::sleep(std::time::Duration::from_nanos(100)); +} + +#[divan::bench] +fn sleep_1us() { + std::thread::sleep(std::time::Duration::from_micros(1)); +} + +#[divan::bench] +fn sleep_100us() { + std::thread::sleep(std::time::Duration::from_micros(100)); +} + +#[divan::bench] +fn sleep_1ms() { + std::thread::sleep(std::time::Duration::from_millis(1)); +}