@@ -11,19 +11,29 @@ fn build_schedule(criterion: &mut Criterion) {
1111
1212 // Use multiple different kinds of label to ensure that dynamic dispatch
1313 // doesn't somehow get optimized away.
14- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , SystemLabel ) ]
14+ #[ derive( Debug , Clone , Copy ) ]
1515 struct NumLabel ( usize ) ;
16- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , SystemLabel ) ]
16+ #[ derive( Debug , Clone , Copy , SystemLabel ) ]
1717 struct DummyLabel ;
1818
19+ impl SystemLabel for NumLabel {
20+ fn as_str ( & self ) -> & ' static str {
21+ let s = self . 0 . to_string ( ) ;
22+ Box :: leak ( s. into_boxed_str ( ) )
23+ }
24+ }
25+
1926 let mut group = criterion. benchmark_group ( "build_schedule" ) ;
2027 group. warm_up_time ( std:: time:: Duration :: from_millis ( 500 ) ) ;
2128 group. measurement_time ( std:: time:: Duration :: from_secs ( 15 ) ) ;
2229
2330 // Method: generate a set of `graph_size` systems which have a One True Ordering.
2431 // Add system to the stage with full constraints. Hopefully this should be maximimally
2532 // difficult for bevy to figure out.
26- let labels: Vec < _ > = ( 0 ..1000 ) . map ( NumLabel ) . collect ( ) ;
33+ // Also, we are performing the `as_label` operation outside of the loop since that
34+ // requires an allocation and a leak. This is not something that would be necessary in a
35+ // real scenario, just a contrivance for the benchmark.
36+ let labels: Vec < _ > = ( 0 ..1000 ) . map ( |i| NumLabel ( i) . as_label ( ) ) . collect ( ) ;
2737
2838 // Benchmark graphs of different sizes.
2939 for graph_size in [ 100 , 500 , 1000 ] {
0 commit comments