@@ -42,10 +42,16 @@ public static void main(String[] args) {
4242 System .out .println ("--- Benchmark 1: each() + entity.get(Component.class) ---" );
4343 runBenchmark ("each+get" , () -> benchmarkEachGet (world , query ));
4444
45- System .out .println ("--- Benchmark 2: iter () + Field<T>.get(i ) ---" );
46- runBenchmark ("iter+Field " , () -> benchmarkIterField ( query ));
45+ System .out .println ("--- Benchmark 2: each () + entity.getMutView(Component.class ) ---" );
46+ runBenchmark ("each+getMutView " , () -> benchmarkEachGetMutView ( world , query ));
4747
48- System .out .println ("--- Benchmark 3: iter() + fieldFloat() (native) ---" );
48+ System .out .println ("--- Benchmark 3: iter() + Field<T>.get(i) ---" );
49+ runBenchmark ("iter+Field+get" , () -> benchmarkIterFieldGet (query ));
50+
51+ System .out .println ("--- Benchmark 4: iter() + Field<T>.getMutView(i) ---" );
52+ runBenchmark ("iter+Field+getMutView" , () -> benchmarkIterFieldGetMutView (query ));
53+
54+ System .out .println ("--- Benchmark 5: iter() + fieldFloat() (native) ---" );
4955 runBenchmark ("iter+native" , () -> benchmarkIterNative (query ));
5056
5157 System .out .println ();
@@ -67,7 +73,20 @@ private static float benchmarkEachGet(World world, Query query) {
6773 return sum [0 ];
6874 }
6975
70- private static float benchmarkIterField (Query query ) {
76+ private static float benchmarkEachGetMutView (World world , Query query ) {
77+ final float [] sum = {0.0f };
78+
79+ query .each (entityId -> {
80+ Entity entity = world .obtainEntity (entityId );
81+ PositionView pos = entity .getMutView (Position .class );
82+ VelocityView vel = entity .getMutView (Velocity .class );
83+ sum [0 ] += pos .x () + pos .y () + vel .dx () + vel .dy ();
84+ });
85+
86+ return sum [0 ];
87+ }
88+
89+ private static float benchmarkIterFieldGet (Query query ) {
7190 final float [] sum = {0.0f };
7291
7392 query .iter (iter -> {
@@ -84,6 +103,23 @@ private static float benchmarkIterField(Query query) {
84103 return sum [0 ];
85104 }
86105
106+ private static float benchmarkIterFieldGetMutView (Query query ) {
107+ final float [] sum = {0.0f };
108+
109+ query .iter (iter -> {
110+ Field <Position > positions = iter .field (Position .class , 0 );
111+ Field <Velocity > velocities = iter .field (Velocity .class , 1 );
112+
113+ for (int i = 0 ; i < iter .count (); i ++) {
114+ PositionView pos = positions .getMutView (i );
115+ VelocityView vel = velocities .getMutView (i );
116+ sum [0 ] += pos .x () + pos .y () + vel .dx () + vel .dy ();
117+ }
118+ });
119+
120+ return sum [0 ];
121+ }
122+
87123 private static float benchmarkIterNative (Query query ) {
88124 final float [] sum = {0.0f };
89125
0 commit comments