-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add benchmarks specifically targeting the use-case of extending a timer by removing and re-registering
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use std::time::Duration; | ||
|
||
use calloop::timer::TimeoutAction; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
fn single(c: &mut Criterion) { | ||
let mut event_loop = calloop::EventLoop::<()>::try_new().unwrap(); | ||
let loop_handle = event_loop.handle(); | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10)); | ||
let mut timeout_token = loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
c.bench_function("extend_single", |b| { | ||
b.iter(|| { | ||
loop_handle.remove(timeout_token); | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10)); | ||
timeout_token = loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
event_loop.dispatch(Some(Duration::ZERO), &mut ()).unwrap(); | ||
}); | ||
}); | ||
} | ||
|
||
fn mixed(c: &mut Criterion) { | ||
let mut event_loop = calloop::EventLoop::<()>::try_new().unwrap(); | ||
let loop_handle = event_loop.handle(); | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10 - 1)); | ||
loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10)); | ||
let mut timeout_token = loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(90 * 10)); | ||
loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
c.bench_function("extend_mixed", |b| { | ||
b.iter(|| { | ||
loop_handle.remove(timeout_token); | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10)); | ||
timeout_token = loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
event_loop.dispatch(Some(Duration::ZERO), &mut ()).unwrap(); | ||
}); | ||
}); | ||
} | ||
|
||
fn mixed_multiple(c: &mut Criterion) { | ||
let mut event_loop = calloop::EventLoop::<()>::try_new().unwrap(); | ||
let loop_handle = event_loop.handle(); | ||
|
||
for _ in 0..1000 { | ||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10 - 1)); | ||
loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
} | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10)); | ||
let mut timeout_token = loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
for _ in 0..1000 { | ||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(90 * 10)); | ||
loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
} | ||
|
||
c.bench_function("extend_mixed_many", |b| { | ||
b.iter(|| { | ||
loop_handle.remove(timeout_token); | ||
|
||
let timer = calloop::timer::Timer::from_duration(Duration::from_secs(60 * 10)); | ||
timeout_token = loop_handle | ||
.insert_source(timer, |_, _, _| TimeoutAction::Drop) | ||
.unwrap(); | ||
|
||
event_loop.dispatch(Some(Duration::ZERO), &mut ()).unwrap(); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, single, mixed, mixed_multiple); | ||
criterion_main!(benches); |