File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 1+ use std:: pin:: Pin ;
2+
13use criterion:: { criterion_group, criterion_main, Criterion } ;
2- use event_listener:: Event ;
4+ use event_listener:: { Event , EventListener } ;
35
46const COUNT : usize = 8000 ;
57
68fn bench_events ( c : & mut Criterion ) {
79 c. bench_function ( "notify_and_wait" , |b| {
810 let ev = Event :: new ( ) ;
9- b. iter ( || {
10- let mut handles = Vec :: with_capacity ( COUNT ) ;
11+ let mut handles = Vec :: with_capacity ( COUNT ) ;
12+ for _ in 0 ..COUNT {
13+ handles. push ( EventListener :: new ( & ev) ) ;
14+ }
1115
12- for _ in 0 ..COUNT {
13- handles. push ( ev. listen ( ) ) ;
16+ b. iter ( || {
17+ for handle in & mut handles {
18+ // SAFETY: The handle is not moved out.
19+ let listener = unsafe { Pin :: new_unchecked ( handle) } ;
20+ listener. listen ( ) ;
1421 }
1522
1623 ev. notify ( COUNT ) ;
1724
18- for mut handle in handles {
19- handle. as_mut ( ) . wait ( ) ;
25+ for handle in & mut handles {
26+ // SAFETY: The handle is not moved out.
27+ let listener = unsafe { Pin :: new_unchecked ( handle) } ;
28+ listener. wait ( ) ;
2029 }
2130 } ) ;
2231 } ) ;
You can’t perform that action at this time.
0 commit comments