@@ -11,18 +11,18 @@ fn create_anxious_state_with_time(prev_time: SystemTime) -> AnxiousState {
1111
1212fn create_test_events ( ) -> Vec < InputEvent > {
1313 vec ! [
14- // High-res wheel events (these get processed)
15- InputEvent :: new ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL_HI_RES . 0 , 120 ) ,
16- InputEvent :: new ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL_HI_RES . 0 , 240 ) ,
17- InputEvent :: new ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL_HI_RES . 0 , 360 ) ,
14+ // High-res wheel events (these get processed) - with proper timestamps
15+ InputEvent :: new_now ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL_HI_RES . 0 , 120 ) ,
16+ InputEvent :: new_now ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL_HI_RES . 0 , 240 ) ,
17+ InputEvent :: new_now ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL_HI_RES . 0 , 360 ) ,
1818
1919 // Regular wheel events (these get dropped)
20- InputEvent :: new ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL . 0 , 1 ) ,
21- InputEvent :: new ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL . 0 , -1 ) ,
20+ InputEvent :: new_now ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL . 0 , 1 ) ,
21+ InputEvent :: new_now ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_WHEEL . 0 , -1 ) ,
2222
2323 // Other events (these get passed through)
24- InputEvent :: new ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_X . 0 , 10 ) ,
25- InputEvent :: new ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_Y . 0 , 5 ) ,
24+ InputEvent :: new_now ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_X . 0 , 10 ) ,
25+ InputEvent :: new_now ( EventType :: RELATIVE . 0 , RelativeAxisCode :: REL_Y . 0 , 5 ) ,
2626 ]
2727}
2828
@@ -46,10 +46,10 @@ fn benchmark_apply_anxious_scroll(c: &mut Criterion) {
4646 // Use a fixed timestamp to avoid SystemTime overflow issues
4747 let base_time = UNIX_EPOCH + Duration :: from_secs ( 1000000000 ) ; // Far in the future
4848 let mut state = create_anxious_state_with_time ( base_time) ;
49+ let timestamp = base_time + * elapsed; // Pre-compute timestamp outside hot path
4950
5051 b. iter ( || {
51- // Create a new timestamp for each iteration
52- let timestamp = base_time + * elapsed;
52+ // Only measure the hot path: apply_anxious_scroll call
5353 black_box ( apply_anxious_scroll (
5454 black_box ( * value) ,
5555 black_box ( timestamp) ,
@@ -84,9 +84,10 @@ fn benchmark_apply_anxious_scroll(c: &mut Criterion) {
8484 |b, params| {
8585 let base_time = UNIX_EPOCH + Duration :: from_secs ( 1000000000 ) ;
8686 let mut state = create_anxious_state_with_time ( base_time) ;
87+ let timestamp = base_time + Duration :: from_millis ( 10 ) ; // Pre-compute timestamp outside hot path
8788
8889 b. iter ( || {
89- let timestamp = base_time + Duration :: from_millis ( 10 ) ;
90+ // Only measure the hot path: apply_anxious_scroll call
9091 black_box ( apply_anxious_scroll (
9192 black_box ( 10.0 ) ,
9293 black_box ( timestamp) ,
@@ -120,48 +121,31 @@ fn benchmark_event_processing(c: &mut Criterion) {
120121 let base_time = UNIX_EPOCH + Duration :: from_secs ( 1000000000 ) ;
121122 let mut state_clone = create_anxious_state_with_time ( base_time) ;
122123
123- // Process events but skip the ones that would cause timestamp issues
124- let mut processed_events = Vec :: new ( ) ;
125- for event in & events {
126- if event. event_type ( ) == EventType :: RELATIVE
127- && event. code ( ) == RelativeAxisCode :: REL_WHEEL_HI_RES . 0 {
128- // Skip processing to avoid timestamp calculation issues
129- // Just pass through the event
130- processed_events. push ( * event) ;
131- } else if event. event_type ( ) == EventType :: RELATIVE
132- && event. code ( ) == RelativeAxisCode :: REL_WHEEL . 0 {
133- // Drop event
134- continue ;
135- } else {
136- // Pass through all other events unchanged
137- processed_events. push ( * event) ;
138- }
139- }
140- black_box ( processed_events)
124+ // Use the actual process_events function - this is the real hot path
125+ black_box ( process_events (
126+ black_box ( events. iter ( ) . cloned ( ) ) ,
127+ black_box ( & params) ,
128+ black_box ( & mut state_clone) ,
129+ ) )
141130 } )
142131 } ,
143132 ) ;
144133 }
145134
146- // Test event filtering performance (without anxious scroll calculation)
147- group. bench_function ( "event_filtering " , |b| {
135+ // Test realistic event processing with proper timestamps
136+ group. bench_function ( "realistic_event_processing " , |b| {
148137 let events = create_test_events ( ) ;
138+ let params = AnxiousParams :: default ( ) ;
139+ let base_time = UNIX_EPOCH + Duration :: from_secs ( 1000000000 ) ;
149140
150141 b. iter ( || {
151- let mut filtered_events = Vec :: new ( ) ;
152- for event in & events {
153- if event. event_type ( ) == EventType :: RELATIVE
154- && event. code ( ) == RelativeAxisCode :: REL_WHEEL_HI_RES . 0 {
155- filtered_events. push ( * event) ;
156- } else if event. event_type ( ) == EventType :: RELATIVE
157- && event. code ( ) == RelativeAxisCode :: REL_WHEEL . 0 {
158- // Drop event
159- continue ;
160- } else {
161- filtered_events. push ( * event) ;
162- }
163- }
164- black_box ( filtered_events)
142+ let mut state_clone = create_anxious_state_with_time ( base_time) ;
143+ // Use the actual process_events function with proper timestamps
144+ black_box ( process_events (
145+ black_box ( events. iter ( ) . cloned ( ) ) ,
146+ black_box ( & params) ,
147+ black_box ( & mut state_clone) ,
148+ ) )
165149 } )
166150 } ) ;
167151
0 commit comments