@@ -39,11 +39,11 @@ public static void main(String[] args) {
3939 System .out .println ("Query matches " + query .count () + " entities" );
4040 System .out .println ();
4141
42- System .out .println ("--- Benchmark 1: each() + entity.get( Component.class) ---" );
43- runBenchmark ("each+get" , () -> benchmarkEachGet ( world , query ));
42+ System .out .println ("--- Benchmark 1: each(Component.class, Component.class, ... ) ---" );
43+ runBenchmark ("each+get" , () -> benchmarkEach ( query ));
4444
45- System .out .println ("--- Benchmark 2: each() + entity.getMutView( Component.class) ---" );
46- runBenchmark ("each+getMutView" , () -> benchmarkEachGetMutView ( world , query ));
45+ System .out .println ("--- Benchmark 2: eachView(Component.class, Component.class, ... ) ---" );
46+ runBenchmark ("each+getMutView" , () -> benchmarkEachMutView ( query ));
4747
4848 System .out .println ("--- Benchmark 3: iter() + Field<T>.get(i) ---" );
4949 runBenchmark ("iter+Field+get" , () -> benchmarkIterFieldGet (query ));
@@ -57,28 +57,20 @@ public static void main(String[] args) {
5757 }
5858 }
5959
60- private static float benchmarkEachGet ( World world , Query query ) {
60+ private static float benchmarkEach ( Query query ) {
6161 final float [] sum = {0.0f };
6262
63- query .each (entityId -> {
64- Entity entity = world .obtainEntity (entityId );
65- Position pos = entity .get (Position .class );
66- Velocity vel = entity .get (Velocity .class );
67- sum [0 ] += pos .x () + pos .y () + vel .dx () + vel .dy ();
68- });
63+ query .each (Position .class , Velocity .class , (pos , vel )
64+ -> sum [0 ] += pos .x () + pos .y () + vel .dx () + vel .dy ());
6965
7066 return sum [0 ];
7167 }
7268
73- private static float benchmarkEachGetMutView ( World world , Query query ) {
69+ private static float benchmarkEachMutView ( Query query ) {
7470 final float [] sum = {0.0f };
7571
76- query .each (entityId -> {
77- Entity entity = world .obtainEntity (entityId );
78- PositionView pos = entity .getMutView (Position .class );
79- VelocityView vel = entity .getMutView (Velocity .class );
80- sum [0 ] += pos .x () + pos .y () + vel .dx () + vel .dy ();
81- });
72+ query .eachView (Position .class , Velocity .class , (PositionView posView , VelocityView velView )
73+ -> sum [0 ] += posView .x () + posView .y () + velView .dx () + velView .dy ());
8274
8375 return sum [0 ];
8476 }
0 commit comments