@@ -10,18 +10,20 @@ use bevy::{
10
10
app:: { Last , Plugin , PostUpdate , Startup , Update } ,
11
11
asset:: { AssetServer , Handle } ,
12
12
ecs:: {
13
+ component:: Component ,
13
14
event:: { Event , Events } ,
14
15
schedule:: { IntoSystemConfigs , SystemConfigs } ,
15
- system:: { IntoSystem , Local , Res , SystemState } ,
16
+ system:: { IntoSystem , Local , Res , Resource , SystemState } ,
16
17
world:: { FromWorld , Mut } ,
17
18
} ,
18
19
prelude:: { Entity , World } ,
19
- reflect:: TypeRegistry ,
20
+ reflect:: { Reflect , TypeRegistry } ,
20
21
} ;
21
22
use bevy_mod_scripting_core:: {
22
23
asset:: ScriptAsset ,
23
24
bindings:: {
24
- pretty_print:: DisplayWithWorld , script_value:: ScriptValue , WorldAccessGuard , WorldGuard ,
25
+ pretty_print:: DisplayWithWorld , script_value:: ScriptValue , ReflectAccessId ,
26
+ WorldAccessGuard , WorldGuard ,
25
27
} ,
26
28
callback_labels,
27
29
error:: { InteropError , ScriptError } ,
@@ -33,7 +35,7 @@ use bevy_mod_scripting_core::{
33
35
} ;
34
36
use bevy_mod_scripting_functions:: ScriptFunctionsPlugin ;
35
37
use criterion:: { measurement:: Measurement , BatchSize } ;
36
- use rand:: SeedableRng ;
38
+ use rand:: { Rng , SeedableRng } ;
37
39
use test_functions:: { register_test_functions, RNG } ;
38
40
use test_utils:: test_data:: setup_integration_test;
39
41
@@ -468,7 +470,23 @@ pub fn perform_benchmark_with_generator<
468
470
group : & mut criterion:: BenchmarkGroup < M > ,
469
471
batch_size : BatchSize ,
470
472
) {
473
+ #[ derive( Reflect , Component , Resource ) ]
474
+ struct Fake1 ;
475
+ #[ derive( Reflect , Component , Resource ) ]
476
+ struct Fake2 ;
477
+ #[ derive( Reflect , Resource ) ]
478
+ struct Fake3 ;
479
+ #[ derive( Reflect , Resource ) ]
480
+ struct Fake4 ;
481
+ #[ derive( Reflect , Resource ) ]
482
+ struct Fake5 ;
483
+
471
484
let mut world = std:: mem:: take ( setup_integration_test ( |_, _| { } ) . world_mut ( ) ) ;
485
+ let f1 = world. register_component :: < Fake1 > ( ) ;
486
+ let f2 = world. register_component :: < Fake2 > ( ) ;
487
+ let f3 = world. register_resource :: < Fake3 > ( ) ;
488
+ let f4 = world. register_resource :: < Fake4 > ( ) ;
489
+ let f5 = world. register_resource :: < Fake5 > ( ) ;
472
490
473
491
let world_guard = WorldAccessGuard :: new_exclusive ( & mut world) ;
474
492
let mut rng_guard = RNG . lock ( ) . unwrap ( ) ;
@@ -484,6 +502,20 @@ pub fn perform_benchmark_with_generator<
484
502
let mut allocator = allocator. write ( ) ;
485
503
allocator. clean_garbage_allocations ( ) ;
486
504
}
505
+
506
+ // lock a random amount of fake components/resources, to make benchmarks more natural
507
+ for _ in 0 ..rng_guard. random_range ( 0 ..=5 ) {
508
+ // pick random component
509
+ match rng_guard. random_range ( 0 ..=4 ) {
510
+ 0 => world_guard. claim_write_access ( ReflectAccessId :: for_component_id ( f1) ) ,
511
+ 1 => world_guard. claim_write_access ( ReflectAccessId :: for_component_id ( f2) ) ,
512
+ 2 => world_guard. claim_write_access ( ReflectAccessId :: for_component_id ( f3) ) ,
513
+ 3 => world_guard. claim_write_access ( ReflectAccessId :: for_component_id ( f4) ) ,
514
+ 4 => world_guard. claim_write_access ( ReflectAccessId :: for_component_id ( f5) ) ,
515
+ _ => false ,
516
+ } ;
517
+ }
518
+
487
519
(
488
520
generator ( & mut rng_guard, world_guard. clone ( ) ) ,
489
521
world_guard. clone ( ) ,
0 commit comments