@@ -11,19 +11,29 @@ fn build_schedule(criterion: &mut Criterion) {
11
11
12
12
// Use multiple different kinds of label to ensure that dynamic dispatch
13
13
// doesn't somehow get optimized away.
14
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , SystemLabel ) ]
14
+ #[ derive( Debug , Clone , Copy ) ]
15
15
struct NumLabel ( usize ) ;
16
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , SystemLabel ) ]
16
+ #[ derive( Debug , Clone , Copy , SystemLabel ) ]
17
17
struct DummyLabel ;
18
18
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
+
19
26
let mut group = criterion. benchmark_group ( "build_schedule" ) ;
20
27
group. warm_up_time ( std:: time:: Duration :: from_millis ( 500 ) ) ;
21
28
group. measurement_time ( std:: time:: Duration :: from_secs ( 15 ) ) ;
22
29
23
30
// Method: generate a set of `graph_size` systems which have a One True Ordering.
24
31
// Add system to the stage with full constraints. Hopefully this should be maximimally
25
32
// 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 ( ) ;
27
37
28
38
// Benchmark graphs of different sizes.
29
39
for graph_size in [ 100 , 500 , 1000 ] {
0 commit comments