Skip to content

Commit

Permalink
Add basic benchmarks (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Sep 9, 2022
1 parent c36d7d5 commit 5c1ae63
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 @@ -18,4 +18,12 @@ exclude = ["/.*"]
parking = "2.0.0"

[dev-dependencies]
criterion = "0.3.4"
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;

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 5c1ae63

Please sign in to comment.