From 47cea329e85fa56909eb30092815b5181fb54b1a Mon Sep 17 00:00:00 2001 From: John Nunley Date: Fri, 9 Sep 2022 07:30:51 -0700 Subject: [PATCH] bench: Add basic benchmarks Replay of #31 with minor modifications Signed-off-by: John Nunley --- Cargo.toml | 8 ++++++++ benches/bench.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 benches/bench.rs diff --git a/Cargo.toml b/Cargo.toml index 471089f..5afe10e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,4 +25,12 @@ portable-atomic-util = { version = "0.1.5", features = ["alloc"], optional = tru [dev-dependencies] 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 \ No newline at end of file diff --git a/benches/bench.rs b/benches/bench.rs new file mode 100644 index 0000000..c120ee9 --- /dev/null +++ b/benches/bench.rs @@ -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);