Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new benchmark #57

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.vscode
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"piecs": "0.4.0",
"tiny-ecs": "2.0.0",
"uecs": "0.4.2",
"wolf-ecs": "2.1.1"
"wolf-ecs": "2.1.3"
},
"devDependencies": {
"@types/node": "^16.9.1",
Expand Down
25 changes: 13 additions & 12 deletions src/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { fileURLToPath } from "node:url";
import { Worker } from "node:worker_threads";

const LIBRARIES = [
"becsy",
"bitecs",
"ecsy",
"geotic",
"goodluck",
"harmony-ecs",
"javelin-ecs",
"perform-ecs",
"picoes",
"piecs",
"tiny-ecs",
"uecs",
// "becsy",
// "bitecs",
// "ecsy",
// "geotic",
// "goodluck",
// "harmony-ecs",
// "javelin-ecs",
// "perform-ecs",
// "picoes",
// "piecs",
// "tiny-ecs",
// "uecs",
"wolf-ecs",
];

Expand All @@ -26,6 +26,7 @@ const BENCHMARKS = {
frag_iter: 100,
entity_cycle: 1_000,
add_remove: 1_000,
query_stress: 100,
};

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

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

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

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

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

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

return () => {
add(B);
remove(B);
add();
remove();
};
};
}
23 changes: 12 additions & 11 deletions src/cases/wolf-ecs/entity_cycle.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ECS, types } from "wolf-ecs";

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

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

const qA = ecs.createQuery(A);
function create(lB) {
for (let i = 0, l = qA.archetypes.length; i < l; i++) {
const arch = qA.archetypes[i].entities;
function create() {
const lB = B;
for (let i = 0, l = qA.a.length; i < l; i++) {
const arch = qA.a[i].e;
for (let j = 0, l = arch.length; j < l; j++) {
const id1 = ecs.createEntity();
ecs.addComponent(id1, lB);
const id = ecs.createEntity();
ecs.addComponent(id, lB);
const id2 = ecs.createEntity();
ecs.addComponent(id2, lB);
}
Expand All @@ -21,21 +22,21 @@ export default (count) => {

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

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

return () => {
create(B);
create();
destroy();
};
};
}
26 changes: 13 additions & 13 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";

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

const cmps = [];
Expand All @@ -12,26 +12,26 @@ export default (count) => {
const data = ecs.defineComponent(types.i32);

const dataQuery = ecs.createQuery(data);
function dataSystem(lData) {
for (let i = 0, l = dataQuery.archetypes.length; i < l; i++) {
const arch = dataQuery.archetypes[i].entities;
function dataSystem() {
for (let i = 0, l = dataQuery.a.length; i < l; i++) {
const arch = dataQuery.a[i].e;
for (let j = 0, l = arch.length; j < l; j++) {
lData[arch[j]] *= 2;
data[arch[j]] *= 2;
}
}
}

const zQuery = ecs.createQuery(z);
function zSystem(lZ) {
for (let i = 0, l = zQuery.archetypes.length; i < l; i++) {
const arch = zQuery.archetypes[i].entities;
function zSystem() {
for (let i = 0, l = zQuery.a.length; i < l; i++) {
const arch = zQuery.a[i].e;
for (let j = 0, l = arch.length; j < l; j++) {
lZ[arch[j]] *= 2;
z[arch[j]] *= 2;
}
}
}

for (let i = 0; i < count; i++) {
for (let i = 0; i < n; i++) {
for (let i = 0; i < cmps.length; i++) {
const id = ecs.createEntity();
ecs.addComponent(id, cmps[i]);
Expand All @@ -42,7 +42,7 @@ export default (count) => {
}

return () => {
dataSystem(data);
zSystem(z);
dataSystem();
zSystem();
};
};
}
15 changes: 8 additions & 7 deletions src/cases/wolf-ecs/packed_1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ECS, types } from "wolf-ecs";

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

const A = ecs.defineComponent(types.u32);
Expand All @@ -10,16 +10,17 @@ export default (count) => {
const E = ecs.defineComponent(types.u32);

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

for (let i = 0; i < count; i++) {
for (let i = 0; i < n; i++) {
ecs.createEntity();
ecs.addComponent(i, A);
A[i] = 1;
Expand All @@ -34,6 +35,6 @@ export default (count) => {
}

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

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

const A = ecs.defineComponent(types.u32);
Expand All @@ -10,56 +10,61 @@ export default (count) => {
const E = ecs.defineComponent(types.u32);

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

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

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

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

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

for (let i = 0; i < count; i++) {
for (let i = 0; i < n; i++) {
ecs.createEntity();
ecs.addComponent(i, A);
A[i] = 1;
Expand All @@ -74,10 +79,10 @@ export default (count) => {
}

return () => {
sysA(A);
sysB(B);
sysC(C);
sysD(D);
sysE(E);
sysA();
sysB();
sysC();
sysD();
sysE();
};
};
}
Loading