Skip to content

Commit

Permalink
Add query_stress benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderShadow8 committed Jan 30, 2022
1 parent 31bd3bc commit dce2cd0
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 198 deletions.
1 change: 1 addition & 0 deletions src/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const BENCHMARKS = {
frag_iter: 100,
entity_cycle: 1_000,
add_remove: 1_000,
query_stress: 100,
};

let libraries = [];
Expand Down
49 changes: 23 additions & 26 deletions src/cases/wolf-ecs/add_remove.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
import {ECS, types} from "wolf-ecs"
import { ECS, types } from "wolf-ecs";

export default function(n) {
const ecs = new ECS()
export default function (n) {
const ecs = new ECS();

const A = ecs.defineComponent()
const B = ecs.defineComponent()
const A = ecs.defineComponent();
const B = ecs.defineComponent();

const qA = ecs.createQuery(A)
const qA = ecs.createQuery(A);
function add() {
const lB = B
for(let i = 0; i < qA.length; i++) {
const arch = qA[i]
for(let j = arch.length - 1; j >= 0; j--) {
ecs.addComponent(arch[j], lB)
const lB = B;
for (let i = 0; i < qA.length; i++) {
const arch = qA[i];
for (let j = arch.length - 1; j >= 0; j--) {
ecs.addComponent(arch[j], lB);
}
}
}

const qB = ecs.createQuery(B)
const qB = ecs.createQuery(B);
function remove() {
const lB = B
for(let i = 0; i < qB.length; i++) {
const arch = qB[i]
for(let j = arch.length - 1; j >= 0; j--) {
ecs.removeComponent(arch[j], lB)
const lB = B;
for (let i = 0; i < qB.length; i++) {
const arch = qB[i];
for (let j = arch.length - 1; j >= 0; j--) {
ecs.removeComponent(arch[j], lB);
}
}
}

for(let i = 0; i < n; i++) {
ecs.createEntity()
ecs.addComponent(i, A)
for (let i = 0; i < n; i++) {
ecs.createEntity();
ecs.addComponent(i, A);
}

add()
remove()

return () => {
add()
remove()
}
add();
remove();
};
}
53 changes: 25 additions & 28 deletions src/cases/wolf-ecs/entity_cycle.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
import {ECS, types} from "wolf-ecs"
import { ECS, types } from "wolf-ecs";

export default function(n) {
const ecs = new ECS()
export default function (n) {
const ecs = new ECS();

const A = ecs.defineComponent()
const B = ecs.defineComponent()
const A = ecs.defineComponent();
const B = ecs.defineComponent();

const qA = ecs.createQuery(A)
const qA = ecs.createQuery(A);
function create() {
const lB = B
for(let i = 0, l = qA.length; i < l; i++) {
const arch = qA[i]
for(let j = 0, l = arch.length; j < l; j++) {
const id = ecs.createEntity()
ecs.addComponent(id, lB)
const id2 = ecs.createEntity()
ecs.addComponent(id2, lB)
const lB = B;
for (let i = 0, l = qA.length; i < l; i++) {
const arch = qA[i];
for (let j = 0, l = arch.length; j < l; j++) {
const id = ecs.createEntity();
ecs.addComponent(id, lB);
const id2 = ecs.createEntity();
ecs.addComponent(id2, lB);
}
}
}

const qB = ecs.createQuery(B)
const qB = ecs.createQuery(B);
function destroy() {
for(let i = 0, l = qB.length; i < l; i++) {
const arch = qB[i]
for(let j = arch.length - 1; j >= 0; j--) {
ecs.destroyEntity(arch[j])
for (let i = 0, l = qB.length; i < l; i++) {
const arch = qB[i];
for (let j = arch.length - 1; j >= 0; j--) {
ecs.destroyEntity(arch[j]);
}
}
}

for(let i = 0; i < n; i++) {
ecs.createEntity()
ecs.addComponent(i, A)
for (let i = 0; i < n; i++) {
ecs.createEntity();
ecs.addComponent(i, A);
}

create()
destroy()

return () => {
create()
destroy()
}
create();
destroy();
};
}
6 changes: 3 additions & 3 deletions src/cases/wolf-ecs/frag_iter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ECS, types} from "wolf-ecs"
import { ECS, types } from "wolf-ecs";

export default function(n) {
export default function (n) {
const ecs = new ECS();

const cmps = [];
Expand Down Expand Up @@ -45,4 +45,4 @@ export default function(n) {
dataSystem();
zSystem();
};
};
}
56 changes: 28 additions & 28 deletions src/cases/wolf-ecs/packed_1.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import {ECS, types} from "wolf-ecs"
import { ECS, types } from "wolf-ecs";

export default function(n) {
const ecs = new ECS()
export default function (n) {
const ecs = new ECS();

const A = ecs.defineComponent(types.u32)
const B = ecs.defineComponent(types.u32)
const C = ecs.defineComponent(types.u32)
const D = ecs.defineComponent(types.u32)
const E = ecs.defineComponent(types.u32)
const A = ecs.defineComponent(types.u32);
const B = ecs.defineComponent(types.u32);
const C = ecs.defineComponent(types.u32);
const D = ecs.defineComponent(types.u32);
const E = ecs.defineComponent(types.u32);

const q = ecs.createQuery(A)
const q = ecs.createQuery(A);
function sys() {
const lA = A
for(let i = 0, l = q.length; i < l; i++) {
const arch = q[i]
for(let j = 0, l = arch.length; j < l; j++) {
lA[arch[j]] *= 2
const lA = A;
for (let i = 0, l = q.length; i < l; i++) {
const arch = q[i];
for (let j = 0, l = arch.length; j < l; j++) {
lA[arch[j]] *= 2;
}
}
}

for(let i = 0; i < n; i++) {
ecs.createEntity()
ecs.addComponent(i, A)
A[i] = 1
ecs.addComponent(i, B)
B[i] = 1
ecs.addComponent(i, C)
C[i] = 1
ecs.addComponent(i, D)
D[i] = 1
ecs.addComponent(i, E)
E[i] = 1
for (let i = 0; i < n; i++) {
ecs.createEntity();
ecs.addComponent(i, A);
A[i] = 1;
ecs.addComponent(i, B);
B[i] = 1;
ecs.addComponent(i, C);
C[i] = 1;
ecs.addComponent(i, D);
D[i] = 1;
ecs.addComponent(i, E);
E[i] = 1;
}

return () => {
sys()
}
sys();
};
}
112 changes: 56 additions & 56 deletions src/cases/wolf-ecs/packed_5.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
import {ECS, types} from "wolf-ecs"
import { ECS, types } from "wolf-ecs";

export default function(n) {
const ecs = new ECS()
export default function (n) {
const ecs = new ECS();

const A = ecs.defineComponent(types.u32)
const B = ecs.defineComponent(types.u32)
const C = ecs.defineComponent(types.u32)
const D = ecs.defineComponent(types.u32)
const E = ecs.defineComponent(types.u32)
const A = ecs.defineComponent(types.u32);
const B = ecs.defineComponent(types.u32);
const C = ecs.defineComponent(types.u32);
const D = ecs.defineComponent(types.u32);
const E = ecs.defineComponent(types.u32);

const qA = ecs.createQuery(A)
const qA = ecs.createQuery(A);
function sysA() {
const lA = A
for(let i = 0, l = qA.length; i < l; i++) {
const arch = qA[i]
for(let j = 0, l = arch.length; j < l; j++) {
lA[arch[j]] *= 2
const lA = A;
for (let i = 0, l = qA.length; i < l; i++) {
const arch = qA[i];
for (let j = 0, l = arch.length; j < l; j++) {
lA[arch[j]] *= 2;
}
}
}

const qB = ecs.createQuery(B)
const qB = ecs.createQuery(B);
function sysB() {
const lB = B
for(let i = 0, l = qB.length; i < l; i++) {
const arch = qB[i]
for(let j = 0, l = arch.length; j < l; j++) {
lB[arch[j]] *= 2
const lB = B;
for (let i = 0, l = qB.length; i < l; i++) {
const arch = qB[i];
for (let j = 0, l = arch.length; j < l; j++) {
lB[arch[j]] *= 2;
}
}
}

const qC = ecs.createQuery(C)
const qC = ecs.createQuery(C);
function sysC() {
const lC = C
for(let i = 0, l = qC.length; i < l; i++) {
const arch = qC[i]
for(let j = 0, l = arch.length; j < l; j++) {
lC[arch[j]] *= 2
const lC = C;
for (let i = 0, l = qC.length; i < l; i++) {
const arch = qC[i];
for (let j = 0, l = arch.length; j < l; j++) {
lC[arch[j]] *= 2;
}
}
}

const qD = ecs.createQuery(D)
const qD = ecs.createQuery(D);
function sysD() {
const lD = D
for(let i = 0, l = qD.length; i < l; i++) {
const arch = qD[i]
for(let j = 0, l = arch.length; j < l; j++) {
lD[arch[j]] *= 2
const lD = D;
for (let i = 0, l = qD.length; i < l; i++) {
const arch = qD[i];
for (let j = 0, l = arch.length; j < l; j++) {
lD[arch[j]] *= 2;
}
}
}

const qE = ecs.createQuery(E)
const qE = ecs.createQuery(E);
function sysE() {
const lE = E
for(let i = 0, l = qE.length; i < l; i++) {
const arch = qE[i]
for(let j = 0, l = arch.length; j < l; j++) {
lE[arch[j]] *= 2
const lE = E;
for (let i = 0, l = qE.length; i < l; i++) {
const arch = qE[i];
for (let j = 0, l = arch.length; j < l; j++) {
lE[arch[j]] *= 2;
}
}
}

for(let i = 0; i < n; i++) {
ecs.createEntity()
ecs.addComponent(i, A)
A[i] = 1
ecs.addComponent(i, B)
B[i] = 1
ecs.addComponent(i, C)
C[i] = 1
ecs.addComponent(i, D)
D[i] = 1
ecs.addComponent(i, E)
E[i] = 1
for (let i = 0; i < n; i++) {
ecs.createEntity();
ecs.addComponent(i, A);
A[i] = 1;
ecs.addComponent(i, B);
B[i] = 1;
ecs.addComponent(i, C);
C[i] = 1;
ecs.addComponent(i, D);
D[i] = 1;
ecs.addComponent(i, E);
E[i] = 1;
}

return () => {
sysA()
sysB()
sysC()
sysD()
sysE()
}
sysA();
sysB();
sysC();
sysD();
sysE();
};
}
Loading

0 comments on commit dce2cd0

Please sign in to comment.