diff --git a/Cargo.toml b/Cargo.toml index feaab45..c34f72b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,13 @@ serde = { version = "1.0", features = ["derive"], optional = true } sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true } sqlite-loadable = { version = "0.0.5", optional = true } +[dev-dependencies] +divan = "0.1" + +[[bench]] +name = "simple" +harness = false + [[bin]] name = "julid-gen" path = "src/bin/gen.rs" diff --git a/benches/simple.rs b/benches/simple.rs new file mode 100644 index 0000000..ac67042 --- /dev/null +++ b/benches/simple.rs @@ -0,0 +1,16 @@ +use divan::black_box; +use julid::Julid; + +fn main() { + divan::main(); +} + +#[divan::bench] +fn jbench() { + for _ in 0..1_000_000 { + let x = black_box(Julid::new()); + if x < 1u128.into() { + println!("that's weird"); + } + } +} diff --git a/examples/benchmark.rs b/examples/benchmark.rs deleted file mode 100644 index 1e8bfd2..0000000 --- a/examples/benchmark.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::time::Instant; - -use clap::Parser; -use julid::Julid; - -#[derive(Debug, Parser)] -struct Cli { - #[clap( - long, - short, - help = "Number of Julids to generate", - default_value_t = 2_000 - )] - pub num: usize, -} - -fn main() { - let cli = Cli::parse(); - let num = cli.num; - let mut v = Vec::with_capacity(num); - let start = Instant::now(); - for _ in 0..num { - v.push(Julid::new()); - } - let end = Instant::now(); - let dur = (end - start).as_micros(); - - for id in v.iter() { - eprintln!( - "{id}: created_at {}; counter: {}; sortable: {}", - id.created_at(), - id.counter(), - id.sortable() - ); - } - println!("{num} Julids generated in {dur}us"); -}