julid-rs/examples/benchmark.rs

38 lines
773 B
Rust
Raw Normal View History

2023-07-25 19:04:38 +00:00
use std::time::Instant;
use clap::Parser;
use julid::Julid;
2023-07-25 19:04:38 +00:00
#[derive(Debug, Parser)]
struct Cli {
#[clap(
long,
short,
help = "Number of Julids to generate",
default_value_t = 2_000
)]
pub num: usize,
}
2023-07-25 19:04:38 +00:00
fn main() {
let cli = Cli::parse();
let num = cli.num;
let mut v = Vec::with_capacity(num);
2023-07-25 19:04:38 +00:00
let start = Instant::now();
for _ in 0..num {
2023-07-25 19:04:38 +00:00
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(),
2023-07-25 19:04:38 +00:00
id.counter(),
id.sortable()
);
}
println!("{num} Julids generated in {dur}us");
2023-07-25 19:04:38 +00:00
}