Add Divan benchmarking.
This commit is contained in:
parent
d9e68f057c
commit
34f85a95a0
3 changed files with 23 additions and 37 deletions
|
@ -35,6 +35,13 @@ serde = { version = "1.0", features = ["derive"], optional = true }
|
||||||
sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true }
|
sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true }
|
||||||
sqlite-loadable = { version = "0.0.5", optional = true }
|
sqlite-loadable = { version = "0.0.5", optional = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
divan = "0.1"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "simple"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "julid-gen"
|
name = "julid-gen"
|
||||||
path = "src/bin/gen.rs"
|
path = "src/bin/gen.rs"
|
||||||
|
|
16
benches/simple.rs
Normal file
16
benches/simple.rs
Normal file
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
|
||||||
}
|
|
Loading…
Reference in a new issue