Skip to content

Commit

Permalink
bench: Add basic benchmarks
Browse files Browse the repository at this point in the history
Replay of #31 with minor modifications

Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull committed Apr 18, 2024
1 parent 5511324 commit 1339914
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ portable-atomic-util = { version = "0.1.5", optional = true }
[dev-dependencies]
futures = { version = "0.3", default-features = false, features = ["std"] }
futures-lite = "2.3.0"
criterion = { version = "0.3.4", default-features = false, features = ["cargo_bench_support"] }
waker-fn = "1"

[[bench]]
name = "bench"
harness = false

[lib]
bench = false
26 changes: 26 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use criterion::{criterion_group, criterion_main, Criterion};
use event_listener::{Event, Listener};

const COUNT: usize = 8000;

fn bench_events(c: &mut Criterion) {
c.bench_function("notify_and_wait", |b| {
let ev = Event::new();
b.iter(|| {
let mut handles = Vec::with_capacity(COUNT);

for _ in 0..COUNT {
handles.push(ev.listen());
}

ev.notify(COUNT);

for handle in handles {
handle.wait();
}
});
});
}

criterion_group!(benches, bench_events);
criterion_main!(benches);

0 comments on commit 1339914

Please sign in to comment.