Added a perftest
This commit is contained in:
parent
87389e78eb
commit
21513f69ed
3
perftest/.gitignore
vendored
3
perftest/.gitignore
vendored
@ -26,3 +26,6 @@ buildNumber.properties
|
|||||||
.factorypath
|
.factorypath
|
||||||
.project
|
.project
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# Ignore logs, these came from an error in the VM
|
||||||
|
*.log
|
||||||
|
@ -35,6 +35,11 @@
|
|||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nz.ac.massey.javaecs</groupId>
|
||||||
|
<artifactId>javaecs</artifactId>
|
||||||
|
<version>0.9.2-PRERELEASE</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -17,7 +17,40 @@ public final class App {
|
|||||||
* @param args The arguments of the program.
|
* @param args The arguments of the program.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Engine engine = new Engine();
|
int nEntities = 1_000_000;
|
||||||
|
Engine engine = new Engine(nEntities);
|
||||||
|
|
||||||
|
engine.registerComponent(ComflabulationComponent.class);
|
||||||
|
engine.registerComponent(DirectionComponent.class);
|
||||||
|
engine.registerComponent(PositionComponent.class);
|
||||||
|
|
||||||
|
ComflabSystem comflabSystem = new ComflabSystem(engine);
|
||||||
|
engine.registerSystem(ComflabSystem.class, comflabSystem);
|
||||||
|
|
||||||
|
MovementSystem movementSystem = new MovementSystem(engine);
|
||||||
|
engine.registerSystem(MovementSystem.class, movementSystem);
|
||||||
|
double startTime = System.nanoTime();
|
||||||
|
for (int i = 0; i < nEntities; i++) {
|
||||||
|
Entity entity = engine.createEntity();
|
||||||
|
engine.addComponent(entity, PositionComponent.class, new PositionComponent());
|
||||||
|
engine.addComponent(entity, DirectionComponent.class, new DirectionComponent());
|
||||||
|
|
||||||
|
if (i % 2 != 0){
|
||||||
|
engine.addComponent(entity, ComflabulationComponent.class, new ComflabulationComponent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double endTime = System.nanoTime();
|
||||||
|
|
||||||
|
System.out.println("Entity creation Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + "seconds )");
|
||||||
|
|
||||||
|
Float dt = 1.0f/60.0f;
|
||||||
|
startTime = System.nanoTime();
|
||||||
|
movementSystem.update(dt);
|
||||||
|
comflabSystem.update(dt);
|
||||||
|
endTime = System.nanoTime();
|
||||||
|
|
||||||
|
System.out.println("Time taken: " + (endTime - startTime) / 1e6+ " ms " + "("+ (endTime - startTime) / 1e9 + "seconds )");
|
||||||
|
|
||||||
System.out.println("Hello World!");
|
System.out.println("Hello World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package nz.ac.massey.javaecs.examples.Components;
|
||||||
|
|
||||||
|
public class ComflabulationComponent {
|
||||||
|
public Float thingy;
|
||||||
|
public Integer dingy;
|
||||||
|
public boolean mingy;
|
||||||
|
public String stringy;
|
||||||
|
|
||||||
|
public ComflabulationComponent(Float thingy, Integer dingy, boolean mingy, String stringy){
|
||||||
|
this.thingy = thingy;
|
||||||
|
this.dingy = dingy;
|
||||||
|
this.mingy = mingy;
|
||||||
|
this.stringy = stringy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComflabulationComponent(){
|
||||||
|
thingy = 0.0f;
|
||||||
|
dingy = 0;
|
||||||
|
mingy = false;
|
||||||
|
stringy = "";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package nz.ac.massey.javaecs.examples.Components;
|
||||||
|
|
||||||
|
public class DirectionComponent {
|
||||||
|
public Float x;
|
||||||
|
public Float y;
|
||||||
|
|
||||||
|
public DirectionComponent(Float x, Float y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DirectionComponent(){
|
||||||
|
x = 0.0f;
|
||||||
|
y = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package nz.ac.massey.javaecs.examples.Components;
|
||||||
|
|
||||||
|
public class PositionComponent {
|
||||||
|
public Float x;
|
||||||
|
public Float y;
|
||||||
|
|
||||||
|
public PositionComponent(Float x, Float y){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PositionComponent(){
|
||||||
|
x = 0.0f;
|
||||||
|
y = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package nz.ac.massey.javaecs.examples.Systems;
|
||||||
|
|
||||||
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
import nz.ac.massey.javaecs.ECSSystem;
|
||||||
|
import nz.ac.massey.javaecs.Engine;
|
||||||
|
import nz.ac.massey.javaecs.Entity;
|
||||||
|
import nz.ac.massey.javaecs.examples.Components.ComflabulationComponent;
|
||||||
|
|
||||||
|
public class ComflabSystem extends ECSSystem {
|
||||||
|
Engine ecs;
|
||||||
|
|
||||||
|
public ComflabSystem(Engine ecs){
|
||||||
|
this.ecs = ecs;
|
||||||
|
registrationSet = new BitSet();
|
||||||
|
registrationSet.set(ecs.getComponentIndex(ComflabulationComponent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Float dt) {
|
||||||
|
for (Entity entity : entities) {
|
||||||
|
ComflabulationComponent comflab = (ComflabulationComponent)ecs.getComponentData(entity, ComflabulationComponent.class);
|
||||||
|
comflab.thingy *= 1.000001f;
|
||||||
|
comflab.mingy = !comflab.mingy;
|
||||||
|
comflab.dingy++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package nz.ac.massey.javaecs.examples.Systems;
|
||||||
|
|
||||||
|
import java.lang.management.ThreadInfo;
|
||||||
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
import nz.ac.massey.javaecs.ECSSystem;
|
||||||
|
import nz.ac.massey.javaecs.Engine;
|
||||||
|
import nz.ac.massey.javaecs.Entity;
|
||||||
|
import nz.ac.massey.javaecs.examples.Components.DirectionComponent;
|
||||||
|
import nz.ac.massey.javaecs.examples.Components.PositionComponent;
|
||||||
|
|
||||||
|
public class MovementSystem extends ECSSystem {
|
||||||
|
Engine ecs;
|
||||||
|
|
||||||
|
public MovementSystem(Engine ecs){
|
||||||
|
this.ecs = ecs;
|
||||||
|
registrationSet = new BitSet();
|
||||||
|
registrationSet.set(ecs.getComponentIndex(PositionComponent.class));
|
||||||
|
registrationSet.set(ecs.getComponentIndex(DirectionComponent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Float dt) {
|
||||||
|
for (Entity entity : entities) {
|
||||||
|
PositionComponent position = (PositionComponent)ecs.getComponentData(entity, PositionComponent.class);
|
||||||
|
DirectionComponent direction = (DirectionComponent)ecs.getComponentData(entity, DirectionComponent.class);
|
||||||
|
position.x += direction.x * dt;
|
||||||
|
position.y += direction.y * dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user