File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ exclude = ["/.*"]
18
18
name = " io"
19
19
harness = false
20
20
21
+ [[bench ]]
22
+ name = " timer"
23
+ harness = false
24
+
21
25
[dependencies ]
22
26
async-lock = " 2.6"
23
27
cfg-if = " 1"
@@ -37,7 +41,7 @@ autocfg = "1"
37
41
async-channel = " 1"
38
42
async-net = " 1"
39
43
blocking = " 1"
40
- criterion = " 0.4"
44
+ criterion = { version = " 0.4" , default-features = false , features = [ " cargo_bench_support " ] }
41
45
getrandom = " 0.2.7"
42
46
signal-hook = " 0.3"
43
47
tempfile = " 3"
Original file line number Diff line number Diff line change
1
+ //! Benchmarks for registering timers.
2
+
3
+ use async_io:: Timer ;
4
+ use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
5
+ use futures_lite:: future;
6
+ use std:: time:: Duration ;
7
+
8
+ /// Create a new `Timer` and poll it once to register it into the timer wheel.
9
+ fn make_timer ( ) -> Timer {
10
+ let mut timer = Timer :: after ( Duration :: from_secs ( 1 ) ) ;
11
+ future:: block_on ( future:: poll_once ( & mut timer) ) ;
12
+ timer
13
+ }
14
+
15
+ /// Benchmark the time it takes to register and deregister a timer.
16
+ fn register_timer ( c : & mut Criterion ) {
17
+ let mut group = c. benchmark_group ( "register_timer" ) ;
18
+ for prev_timer_count in [ 0 , 1_000_000 ] {
19
+ // Add timers to the timer wheel.
20
+ let mut timers = Vec :: new ( ) ;
21
+ for _ in 0 ..prev_timer_count {
22
+ timers. push ( make_timer ( ) ) ;
23
+ }
24
+
25
+ // Benchmark registering a timer.
26
+ group. bench_function (
27
+ format ! ( "register_timer.({} previous timers)" , prev_timer_count) ,
28
+ |b| {
29
+ b. iter ( || {
30
+ let timer = make_timer ( ) ;
31
+ black_box ( timer) ;
32
+ } ) ;
33
+ } ,
34
+ ) ;
35
+ }
36
+ }
37
+
38
+ criterion_group ! ( benches, register_timer) ;
39
+ criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments