Skip to content

Commit

Permalink
Add benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
ddmills committed Jan 28, 2021
1 parent 00e930f commit ce5e925
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/bench/benchmark.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Engine from '../../src/Engine';
import Component from '../../src/Component';

describe('benchmark', () => {
let engine, query;

class ComponentA extends Component {}
class ComponentB extends Component {}

it('does 10000 additions and removals', () => {
let time = 0;
const testCount = 10;

for (let i = 0; i < testCount; i++) {
engine = new Engine();

engine.registerComponent(ComponentA);
engine.registerComponent(ComponentB);

query = engine.createQuery({
all: [ComponentA, ComponentB]
});

const start = Date.now();

for (let j = 0; j < 10000; j++) {
const entity = engine.createEntity();

entity.add(ComponentA);
entity.add(ComponentB);
}

const end = Date.now();
const delta = end - start;

console.log(`T${i} ${delta}ms`);

time += delta;
}

const avg = time / testCount;

console.log(`AVG ${avg.toFixed(2)}ms`);
});
});

0 comments on commit ce5e925

Please sign in to comment.