From c990b7f28048649000379c8de129497883bc2033 Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Thu, 5 Aug 2021 16:46:41 +0200 Subject: [PATCH 1/8] Update Becsy --- README.md | 24 ++++++++++++------------ package-lock.json | 14 +++++++------- package.json | 2 +- src/cases/becsy/add_remove.js | 12 ++++++------ src/cases/becsy/entity_cycle.js | 12 ++++++------ src/cases/becsy/frag_iter.js | 8 ++++---- src/cases/becsy/packed_1.js | 8 ++++---- src/cases/becsy/packed_5.js | 24 ++++++++++++------------ src/cases/becsy/simple_iter.js | 16 ++++++++-------- 9 files changed, 60 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 23788c1..7f0cbfa 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,18 @@ A suite of benchmarks designed to test and compare JavaScript ECS library perfor | | packed_1 | packed_5 | simple_iter | frag_iter | entity_cycle | add_remove | | ----------- | -----------: | -----------: | -----------: | -----------: | -----------: | ----------: | -| becsy | 84,273 op/s | 76,489 op/s | 54,115 op/s | 153,480 op/s | 1,896 op/s | 11,223 op/s | -| bitecs | 234,608 op/s | 218,055 op/s | 133,733 op/s | 452,260 op/s | 1,266 op/s | 3,988 op/s | -| ecsy | 9,601 op/s | 7,080 op/s | 3,079 op/s | 23,755 op/s | 31 op/s | 718 op/s | -| flock-ecs | 3,742 op/s | 4,606 op/s | 1,822 op/s | 7,866 op/s | 82 op/s | 18,164 op/s | -| geotic | 34,400 op/s | 43,287 op/s | 27,159 op/s | 46,498 op/s | 29 op/s | 914 op/s | -| goodluck | 46,008 op/s | 53,443 op/s | 27,988 op/s | 102,591 op/s | 13,634 op/s | 92,730 op/s | -| javelin-ecs | 67,306 op/s | 66,801 op/s | 39,770 op/s | 114,093 op/s | 285 op/s | 3,274 op/s | -| makr | 13,253 op/s | 10,086 op/s | 7,135 op/s | 25,167 op/s | 10,752 op/s | 26,686 op/s | -| perform-ecs | 59,418 op/s | 59,047 op/s | 73,860 op/s | 27,874 op/s | 40 op/s | 374 op/s | -| picoes | 26,304 op/s | 6,886 op/s | 4,065 op/s | 12,619 op/s | 1,425 op/s | 3,576 op/s | -| tiny-ecs | 15,788 op/s | 14,873 op/s | 26,729 op/s | 43,586 op/s | 39 op/s | 880 op/s | -| wolf-ecs | 317,003 op/s | 314,997 op/s | 151,010 op/s | 517,377 op/s | 4,019 op/s | 19,486 op/s | +| becsy | 31,365 op/s | 36,042 op/s | 20,042 op/s | 59,558 op/s | 218 op/s | 8,308 op/s | +| bitecs | 236,678 op/s | 224,387 op/s | 122,779 op/s | 453,375 op/s | 1,387 op/s | 3,382 op/s | +| ecsy | 12,589 op/s | 7,537 op/s | 4,609 op/s | 24,726 op/s | 35 op/s | 846 op/s | +| flock-ecs | 3,312 op/s | 3,145 op/s | 1,738 op/s | 7,470 op/s | 94 op/s | 18,144 op/s | +| geotic | 37,355 op/s | 41,713 op/s | 26,426 op/s | 45,248 op/s | 27 op/s | 822 op/s | +| goodluck | 51,630 op/s | 53,048 op/s | 28,136 op/s | 100,559 op/s | 12,679 op/s | 89,410 op/s | +| javelin-ecs | 66,776 op/s | 67,414 op/s | 38,804 op/s | 103,980 op/s | 301 op/s | 3,393 op/s | +| makr | 14,031 op/s | 10,264 op/s | 7,241 op/s | 27,371 op/s | 10,812 op/s | 27,231 op/s | +| perform-ecs | 56,882 op/s | 58,701 op/s | 77,554 op/s | 31,243 op/s | 35 op/s | 314 op/s | +| picoes | 26,502 op/s | 7,274 op/s | 4,518 op/s | 15,414 op/s | 1,372 op/s | 4,061 op/s | +| tiny-ecs | 19,935 op/s | 17,047 op/s | 29,792 op/s | 50,206 op/s | 45 op/s | 1,010 op/s | +| wolf-ecs | 313,292 op/s | 279,654 op/s | 156,069 op/s | 529,318 op/s | 5,256 op/s | 23,150 op/s | The best result for each benchmark is marked in bold text. Note that run to run variance for these benchmarks is typically 1-4%. Any benchmarks within a few percent of each other should be considered “effectively equal”. The above benchmarks are run on node v16.3.0. diff --git a/package-lock.json b/package-lock.json index 546a1c5..9e98ae6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "": { "dependencies": { "@javelin/ecs": "^0.21.0", - "@lastolivegames/becsy": "^0.4.0", + "@lastolivegames/becsy": "^0.7.0", "bitecs": "^0.3.6", "ecsy": "^0.4.2", "flock-ecs": "^0.1.5", @@ -28,9 +28,9 @@ "integrity": "sha512-JqFs3X4Cb2XPOPo93EkLnJ34WX9XMt5cQjx8jRDwDrDmmOp1RLVS/fRDc3buWAarVDk6BekVOzzbfQvQVQBzjQ==" }, "node_modules/@lastolivegames/becsy": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@lastolivegames/becsy/-/becsy-0.4.1.tgz", - "integrity": "sha512-dALRrM8U5l83JjwYNMupmwq90vhckGXZtsRyUG0NEhksUmr9Qq8YQHpS9UFqI7MMx5jJQbG+QzpthG2YOqLh4w==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@lastolivegames/becsy/-/becsy-0.7.0.tgz", + "integrity": "sha512-ilDobAsgE7GNQpdhlIOeW5WW+15QKAhscOSkMrknREq+1wmXYFxLkyZ/bUFGspYxYUP53LPMLlcep5FcI3nZiw==", "engines": { "node": ">=12" } @@ -130,9 +130,9 @@ "integrity": "sha512-JqFs3X4Cb2XPOPo93EkLnJ34WX9XMt5cQjx8jRDwDrDmmOp1RLVS/fRDc3buWAarVDk6BekVOzzbfQvQVQBzjQ==" }, "@lastolivegames/becsy": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@lastolivegames/becsy/-/becsy-0.4.1.tgz", - "integrity": "sha512-dALRrM8U5l83JjwYNMupmwq90vhckGXZtsRyUG0NEhksUmr9Qq8YQHpS9UFqI7MMx5jJQbG+QzpthG2YOqLh4w==" + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@lastolivegames/becsy/-/becsy-0.7.0.tgz", + "integrity": "sha512-ilDobAsgE7GNQpdhlIOeW5WW+15QKAhscOSkMrknREq+1wmXYFxLkyZ/bUFGspYxYUP53LPMLlcep5FcI3nZiw==" }, "@types/node": { "version": "15.6.1", diff --git a/package.json b/package.json index 48970fe..e43625b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@javelin/ecs": "^0.21.0", - "@lastolivegames/becsy": "^0.4.0", + "@lastolivegames/becsy": "^0.7.0", "bitecs": "^0.3.6", "ecsy": "^0.4.2", "flock-ecs": "^0.1.5", diff --git a/src/cases/becsy/add_remove.js b/src/cases/becsy/add_remove.js index cdd919e..9b96df6 100644 --- a/src/cases/becsy/add_remove.js +++ b/src/cases/becsy/add_remove.js @@ -1,6 +1,6 @@ import { System, Type, World } from "@lastolivegames/becsy/perf.js"; -export default (count) => { +export default async (count) => { class A { static schema = { value: Type.int32, @@ -14,26 +14,26 @@ export default (count) => { } class AddB extends System { - entities = this.query((q) => q.all.with(A).but.without(B).write); + entities = this.query((q) => q.current.with(A).but.without(B).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.add(B, { value: 0 }); } } } class RemoveB extends System { - entities = this.query((q) => q.all.with(B).write); + entities = this.query((q) => q.current.with(B).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.remove(B); } } } - const world = new World({ + const world = await World.create({ maxEntities: count, maxShapeChangesPerFrame: count * 3, defs: [A, B, AddB, RemoveB], diff --git a/src/cases/becsy/entity_cycle.js b/src/cases/becsy/entity_cycle.js index 26716f2..e094e2f 100644 --- a/src/cases/becsy/entity_cycle.js +++ b/src/cases/becsy/entity_cycle.js @@ -1,6 +1,6 @@ import { System, Type, World } from "@lastolivegames/becsy/perf.js"; -export default (count) => { +export default async (count) => { class A { static schema = { value: Type.int32, @@ -14,10 +14,10 @@ export default (count) => { } class SpawnB extends System { - entities = this.query((q) => q.all.with(A).also.using(B).write); + entities = this.query((q) => q.current.with(A).also.using(B).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { const value = entity.read(A).value; this.createEntity(B, { value }); this.createEntity(B, { value }); @@ -26,16 +26,16 @@ export default (count) => { } class KillB extends System { - entities = this.query((q) => q.all.with(B).write); + entities = this.query((q) => q.current.with(B).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.delete(); } } } - const world = new World({ + const world = await World.create({ maxEntities: count * 8, maxLimboEntities: 10000, defs: [A, B, SpawnB, KillB], diff --git a/src/cases/becsy/frag_iter.js b/src/cases/becsy/frag_iter.js index 2566cd0..276b342 100644 --- a/src/cases/becsy/frag_iter.js +++ b/src/cases/becsy/frag_iter.js @@ -1,6 +1,6 @@ import { System, Type, World } from "@lastolivegames/becsy/perf.js"; -export default (count) => { +export default async (count) => { const COMPS = Array.from( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", () => @@ -18,16 +18,16 @@ export default (count) => { } class DataSystem extends System { - entities = this.query((q) => q.all.with(Data).write); + entities = this.query((q) => q.current.with(Data).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.write(Data).value *= 2; } } } - const world = new World({ + const world = await World.create({ maxEntities: count * COMPS.length, defs: [COMPS, Data, DataSystem], }); diff --git a/src/cases/becsy/packed_1.js b/src/cases/becsy/packed_1.js index 19d1cf4..36dcf64 100644 --- a/src/cases/becsy/packed_1.js +++ b/src/cases/becsy/packed_1.js @@ -1,6 +1,6 @@ import { System, Type, World } from "@lastolivegames/becsy/perf.js"; -export default (count) => { +export default async (count) => { class A { static schema = { value: Type.int32, @@ -32,16 +32,16 @@ export default (count) => { } class ASystem extends System { - entities = this.query((q) => q.all.with(A).write); + entities = this.query((q) => q.current.with(A).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.write(A).value *= 2; } } } - const world = new World({ + const world = await World.create({ maxEntities: count, defs: [A, B, C, D, E, ASystem], }); diff --git a/src/cases/becsy/packed_5.js b/src/cases/becsy/packed_5.js index de9cae2..8df794b 100644 --- a/src/cases/becsy/packed_5.js +++ b/src/cases/becsy/packed_5.js @@ -1,6 +1,6 @@ import { System, Type, World } from "@lastolivegames/becsy/perf.js"; -export default (count) => { +export default async (count) => { class A { static schema = { value: Type.int32, @@ -32,56 +32,56 @@ export default (count) => { } class ASystem extends System { - entities = this.query((q) => q.all.with(A).write); + entities = this.query((q) => q.current.with(A).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.write(A).value *= 2; } } } class BSystem extends System { - entities = this.query((q) => q.all.with(B).write); + entities = this.query((q) => q.current.with(B).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.write(B).value *= 2; } } } class CSystem extends System { - entities = this.query((q) => q.all.with(C).write); + entities = this.query((q) => q.current.with(C).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.write(C).value *= 2; } } } class DSystem extends System { - entities = this.query((q) => q.all.with(D).write); + entities = this.query((q) => q.current.with(D).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.write(D).value *= 2; } } } class ESystem extends System { - entities = this.query((q) => q.all.with(E).write); + entities = this.query((q) => q.current.with(E).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { entity.write(E).value *= 2; } } } - const world = new World({ + const world = await World.create({ maxEntities: count, defs: [A, B, C, D, E, ASystem, BSystem, CSystem, DSystem, ESystem], }); diff --git a/src/cases/becsy/simple_iter.js b/src/cases/becsy/simple_iter.js index dbd5cf6..9deeb04 100644 --- a/src/cases/becsy/simple_iter.js +++ b/src/cases/becsy/simple_iter.js @@ -1,6 +1,6 @@ import { System, Type, World } from "@lastolivegames/becsy/perf.js"; -export default (count) => { +export default async (count) => { class A { static schema = { value: Type.int32, @@ -32,10 +32,10 @@ export default (count) => { } class ABSystem extends System { - entities = this.query((q) => q.all.with(A).write.with(B).write); + entities = this.query((q) => q.current.with(A).write.with(B).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { const a = entity.write(A); const b = entity.write(B); const x = a.value; @@ -46,10 +46,10 @@ export default (count) => { } class CDSystem extends System { - entities = this.query((q) => q.all.with(C).write.with(D).write); + entities = this.query((q) => q.current.with(C).write.with(D).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { const c = entity.write(C); const d = entity.write(D); const x = c.value; @@ -60,10 +60,10 @@ export default (count) => { } class CESystem extends System { - entities = this.query((q) => q.all.with(C).write.with(E).write); + entities = this.query((q) => q.current.with(C).write.with(E).write); execute() { - for (const entity of this.entities.all) { + for (const entity of this.entities.current) { const c = entity.write(C); const e = entity.write(E); const x = c.value; @@ -73,7 +73,7 @@ export default (count) => { } } - const world = new World({ + const world = await World.create({ maxEntities: count * 4, defs: [A, B, C, D, E, ABSystem, CDSystem, CESystem], }); From af6129ea8eaad8343f23714f22ef7d912f1e864d Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Thu, 5 Aug 2021 16:48:09 +0200 Subject: [PATCH 2/8] Update bitecs --- README.md | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7f0cbfa..970ed41 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A suite of benchmarks designed to test and compare JavaScript ECS library perfor | | packed_1 | packed_5 | simple_iter | frag_iter | entity_cycle | add_remove | | ----------- | -----------: | -----------: | -----------: | -----------: | -----------: | ----------: | | becsy | 31,365 op/s | 36,042 op/s | 20,042 op/s | 59,558 op/s | 218 op/s | 8,308 op/s | -| bitecs | 236,678 op/s | 224,387 op/s | 122,779 op/s | 453,375 op/s | 1,387 op/s | 3,382 op/s | +| bitecs | 235,089 op/s | 207,659 op/s | 115,812 op/s | 451,724 op/s | 1,302 op/s | 4,457 op/s | | ecsy | 12,589 op/s | 7,537 op/s | 4,609 op/s | 24,726 op/s | 35 op/s | 846 op/s | | flock-ecs | 3,312 op/s | 3,145 op/s | 1,738 op/s | 7,470 op/s | 94 op/s | 18,144 op/s | | geotic | 37,355 op/s | 41,713 op/s | 26,426 op/s | 45,248 op/s | 27 op/s | 822 op/s | diff --git a/package-lock.json b/package-lock.json index 9e98ae6..47284ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "dependencies": { "@javelin/ecs": "^0.21.0", "@lastolivegames/becsy": "^0.7.0", - "bitecs": "^0.3.6", + "bitecs": "^0.3.16", "ecsy": "^0.4.2", "flock-ecs": "^0.1.5", "geotic": "^4.1.6", @@ -42,9 +42,9 @@ "dev": true }, "node_modules/bitecs": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/bitecs/-/bitecs-0.3.6.tgz", - "integrity": "sha512-D3W30DejeEDKNRuZba5/9k2H33lDzSe0H1KtX8qQEMYm4yyaHul8YzsXp2fjwRhD4/+O3NK2absqj6J1KXhYOA==" + "version": "0.3.16", + "resolved": "https://registry.npmjs.org/bitecs/-/bitecs-0.3.16.tgz", + "integrity": "sha512-FmEiLAPCVRypND0Z9a2UdyYS5eEO8ZmcRZtWfnhxuHhokFCjf4BKlHO0ZEb36d0DSd+1ArLjOxXx5c4KJq5yPg==" }, "node_modules/camelcase": { "version": "6.0.0", @@ -141,9 +141,9 @@ "dev": true }, "bitecs": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/bitecs/-/bitecs-0.3.6.tgz", - "integrity": "sha512-D3W30DejeEDKNRuZba5/9k2H33lDzSe0H1KtX8qQEMYm4yyaHul8YzsXp2fjwRhD4/+O3NK2absqj6J1KXhYOA==" + "version": "0.3.16", + "resolved": "https://registry.npmjs.org/bitecs/-/bitecs-0.3.16.tgz", + "integrity": "sha512-FmEiLAPCVRypND0Z9a2UdyYS5eEO8ZmcRZtWfnhxuHhokFCjf4BKlHO0ZEb36d0DSd+1ArLjOxXx5c4KJq5yPg==" }, "camelcase": { "version": "6.0.0", diff --git a/package.json b/package.json index e43625b..5c0bc4d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dependencies": { "@javelin/ecs": "^0.21.0", "@lastolivegames/becsy": "^0.7.0", - "bitecs": "^0.3.6", + "bitecs": "^0.3.16", "ecsy": "^0.4.2", "flock-ecs": "^0.1.5", "geotic": "^4.1.6", From 29584838b0ddc10715ff4c8684f54c586e411307 Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Thu, 5 Aug 2021 16:52:28 +0200 Subject: [PATCH 3/8] Update Javelin ECS --- README.md | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 970ed41..a8eb097 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A suite of benchmarks designed to test and compare JavaScript ECS library perfor | flock-ecs | 3,312 op/s | 3,145 op/s | 1,738 op/s | 7,470 op/s | 94 op/s | 18,144 op/s | | geotic | 37,355 op/s | 41,713 op/s | 26,426 op/s | 45,248 op/s | 27 op/s | 822 op/s | | goodluck | 51,630 op/s | 53,048 op/s | 28,136 op/s | 100,559 op/s | 12,679 op/s | 89,410 op/s | -| javelin-ecs | 66,776 op/s | 67,414 op/s | 38,804 op/s | 103,980 op/s | 301 op/s | 3,393 op/s | +| javelin-ecs | 68,278 op/s | 68,148 op/s | 42,285 op/s | 118,208 op/s | 326 op/s | 3,479 op/s | | makr | 14,031 op/s | 10,264 op/s | 7,241 op/s | 27,371 op/s | 10,812 op/s | 27,231 op/s | | perform-ecs | 56,882 op/s | 58,701 op/s | 77,554 op/s | 31,243 op/s | 35 op/s | 314 op/s | | picoes | 26,502 op/s | 7,274 op/s | 4,518 op/s | 15,414 op/s | 1,372 op/s | 4,061 op/s | diff --git a/package-lock.json b/package-lock.json index 47284ea..fe31ced 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "packages": { "": { "dependencies": { - "@javelin/ecs": "^0.21.0", + "@javelin/ecs": "^0.22.0", "@lastolivegames/becsy": "^0.7.0", "bitecs": "^0.3.16", "ecsy": "^0.4.2", @@ -23,9 +23,9 @@ } }, "node_modules/@javelin/ecs": { - "version": "0.21.2", - "resolved": "https://registry.npmjs.org/@javelin/ecs/-/ecs-0.21.2.tgz", - "integrity": "sha512-JqFs3X4Cb2XPOPo93EkLnJ34WX9XMt5cQjx8jRDwDrDmmOp1RLVS/fRDc3buWAarVDk6BekVOzzbfQvQVQBzjQ==" + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/@javelin/ecs/-/ecs-0.22.0.tgz", + "integrity": "sha512-zFTu2LeNCBIKAx/kyL1mVRRuokumqVKwLUE5S1pj7anPOXfNa5NN8MY3PALeIMCZpqGsktTCNOEX+s2fDJcG5Q==" }, "node_modules/@lastolivegames/becsy": { "version": "0.7.0", @@ -125,9 +125,9 @@ }, "dependencies": { "@javelin/ecs": { - "version": "0.21.2", - "resolved": "https://registry.npmjs.org/@javelin/ecs/-/ecs-0.21.2.tgz", - "integrity": "sha512-JqFs3X4Cb2XPOPo93EkLnJ34WX9XMt5cQjx8jRDwDrDmmOp1RLVS/fRDc3buWAarVDk6BekVOzzbfQvQVQBzjQ==" + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/@javelin/ecs/-/ecs-0.22.0.tgz", + "integrity": "sha512-zFTu2LeNCBIKAx/kyL1mVRRuokumqVKwLUE5S1pj7anPOXfNa5NN8MY3PALeIMCZpqGsktTCNOEX+s2fDJcG5Q==" }, "@lastolivegames/becsy": { "version": "0.7.0", diff --git a/package.json b/package.json index 5c0bc4d..cd72dcc 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "start": "node src/bench.js" }, "dependencies": { - "@javelin/ecs": "^0.21.0", + "@javelin/ecs": "^0.22.0", "@lastolivegames/becsy": "^0.7.0", "bitecs": "^0.3.16", "ecsy": "^0.4.2", From 06d6303b1ee4d47224214d745063f87e93447dcb Mon Sep 17 00:00:00 2001 From: Florent Cailhol Date: Thu, 5 Aug 2021 16:53:17 +0200 Subject: [PATCH 4/8] Update types --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index fe31ced..65d52d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "wolf-ecs": "^0.8.2" }, "devDependencies": { - "@types/node": "^15.6.1" + "@types/node": "^16.4.12" } }, "node_modules/@javelin/ecs": { @@ -36,9 +36,9 @@ } }, "node_modules/@types/node": { - "version": "15.6.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz", - "integrity": "sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==", + "version": "16.4.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.12.tgz", + "integrity": "sha512-zxrTNFl9Z8boMJXs6ieqZP0wAhvkdzmHSxTlJabM16cf5G9xBc1uPRH5Bbv2omEDDiM8MzTfqTJXBf0Ba4xFWA==", "dev": true }, "node_modules/bitecs": { @@ -135,9 +135,9 @@ "integrity": "sha512-ilDobAsgE7GNQpdhlIOeW5WW+15QKAhscOSkMrknREq+1wmXYFxLkyZ/bUFGspYxYUP53LPMLlcep5FcI3nZiw==" }, "@types/node": { - "version": "15.6.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-15.6.1.tgz", - "integrity": "sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==", + "version": "16.4.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.12.tgz", + "integrity": "sha512-zxrTNFl9Z8boMJXs6ieqZP0wAhvkdzmHSxTlJabM16cf5G9xBc1uPRH5Bbv2omEDDiM8MzTfqTJXBf0Ba4xFWA==", "dev": true }, "bitecs": { diff --git a/package.json b/package.json index cd72dcc..759c52d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "wolf-ecs": "^0.8.2" }, "devDependencies": { - "@types/node": "^15.6.1" + "@types/node": "^16.4.12" } } From 07d4bae341fea2fdcd26b78157e340d2e502c982 Mon Sep 17 00:00:00 2001 From: EnderShadow8 <69184571+EnderShadow8@users.noreply.github.com> Date: Tue, 1 Jun 2021 08:51:18 +0800 Subject: [PATCH 5/8] Add WolfECS --- package-lock.json | 14 ++-- package.json | 2 +- src/cases/wolf-ecs/add_remove.js | 38 +++++----- src/cases/wolf-ecs/entity_cycle.js | 50 ++++++------- src/cases/wolf-ecs/frag_iter.js | 40 +++++----- src/cases/wolf-ecs/packed_1.js | 56 +++++++------- src/cases/wolf-ecs/packed_5.js | 112 ++++++++++++++-------------- src/cases/wolf-ecs/simple_iter.js | 114 ++++++++++++++--------------- 8 files changed, 213 insertions(+), 213 deletions(-) diff --git a/package-lock.json b/package-lock.json index 65d52d2..a4dfa36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "perform-ecs": "^0.7.8", "picoes": "^1.0.0", "tiny-ecs": "^2.0.0", - "wolf-ecs": "^0.8.2" + "wolf-ecs": "^2.0.0" }, "devDependencies": { "@types/node": "^16.4.12" @@ -118,9 +118,9 @@ "integrity": "sha1-+DOIgWkWBk2UYAjZrrKXyqq/ODs=" }, "node_modules/wolf-ecs": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-0.8.2.tgz", - "integrity": "sha512-4d028ZW3qKTeJai6T3pDxQoYzDFaztx/NS/J8IScpiiqMYOpbzNEqS1m/GQz794hC9N4anzRcHjlxoL7Vm+T+g==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-2.0.0.tgz", + "integrity": "sha512-7KEps7Nzu0YeHlWZfr0u1ThUYCbgHtxpqkvVxyliEvcMeATyoJJ0oUfGpsILKU7bRqttwy3vYZDm/pBMBxXAlw==" } }, "dependencies": { @@ -208,9 +208,9 @@ "integrity": "sha1-+DOIgWkWBk2UYAjZrrKXyqq/ODs=" }, "wolf-ecs": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-0.8.2.tgz", - "integrity": "sha512-4d028ZW3qKTeJai6T3pDxQoYzDFaztx/NS/J8IScpiiqMYOpbzNEqS1m/GQz794hC9N4anzRcHjlxoL7Vm+T+g==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-2.0.0.tgz", + "integrity": "sha512-7KEps7Nzu0YeHlWZfr0u1ThUYCbgHtxpqkvVxyliEvcMeATyoJJ0oUfGpsILKU7bRqttwy3vYZDm/pBMBxXAlw==" } } } diff --git a/package.json b/package.json index 759c52d..b7a32a5 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "perform-ecs": "^0.7.8", "picoes": "^1.0.0", "tiny-ecs": "^2.0.0", - "wolf-ecs": "^0.8.2" + "wolf-ecs": "^2.0.0" }, "devDependencies": { "@types/node": "^16.4.12" diff --git a/src/cases/wolf-ecs/add_remove.js b/src/cases/wolf-ecs/add_remove.js index 1316187..659e83f 100644 --- a/src/cases/wolf-ecs/add_remove.js +++ b/src/cases/wolf-ecs/add_remove.js @@ -1,37 +1,37 @@ -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() - ecs.defineComponent("A", types.u32); - ecs.defineComponent("B", types.u32); + ecs.defineComponent("A", types.u32) + ecs.defineComponent("B", types.u32) - const qA = ecs.createQuery("A"); - const qB = ecs.createQuery("B"); + const qA = ecs.createQuery("A") + const qB = ecs.createQuery("B") function add() { - for (let i = 0, l = qA.archetypes.length; i < l; i++) { - for (let j of qA.archetypes[i].entities) { - ecs.addComponent(j, "B"); + for(let i = 0, l = qA.archetypes.length; i < l; i++) { + for(let j of qA.archetypes[i].entities) { + ecs.addComponent(j, "B") } } } function remove() { - for (let i = 0, l = qB.archetypes.length; i < l; i++) { - for (let j of qB.archetypes[i].entities) { - ecs.removeComponent(j, "B"); + for(let i = 0, l = qB.archetypes.length; i < l; i++) { + for(let j of qB.archetypes[i].entities) { + ecs.removeComponent(j, "B") } } } - 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") } return () => { - add(); - remove(); - }; + add() + remove() + } } diff --git a/src/cases/wolf-ecs/entity_cycle.js b/src/cases/wolf-ecs/entity_cycle.js index e86548f..9d1647f 100644 --- a/src/cases/wolf-ecs/entity_cycle.js +++ b/src/cases/wolf-ecs/entity_cycle.js @@ -1,44 +1,44 @@ -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() - ecs.defineComponent("A"); - ecs.defineComponent("B"); + ecs.defineComponent("A") + ecs.defineComponent("B") - const qA = ecs.createQuery("A"); - const qB = ecs.createQuery("B"); + const qA = ecs.createQuery("A") + const qB = ecs.createQuery("B") function create() { - for (let i = 0, l = qA.archetypes.length; i < l; i++) { - for (let j = 0, l = qA.archetypes[i].entities.length; j < l; j++) { - const id = ecs.createEntity(); - ecs.addComponent(id, "B"); - const id2 = ecs.createEntity(); - ecs.addComponent(id2, "B"); + for(let i = 0, l = qA.archetypes.length; i < l; i++) { + for(let j = 0, l = qA.archetypes[i].entities.length; j < l; j++) { + const id = ecs.createEntity() + ecs.addComponent(id, "B") + const id2 = ecs.createEntity() + ecs.addComponent(id2, "B") } } } function destroy() { - for (let i = 0, l = qB.archetypes.length; i < l; i++) { - for (let j of qB.archetypes[i].entities) { - ecs.destroyEntity(j); + for(let i = 0, l = qB.archetypes.length; i < l; i++) { + for(let j of qB.archetypes[i].entities) { + ecs.destroyEntity(j) } } } - for (let i = 0; i < n; i++) { - ecs.createEntity(); - ecs.addComponent(i, "A"); - ecs.components.A[i] = 1; + for(let i = 0; i < n; i++) { + ecs.createEntity() + ecs.addComponent(i, "A") + ecs.components.A[i] = 1 } - create(); - destroy(); + create() + destroy() return () => { - create(); - destroy(); - }; + create() + destroy() + } } diff --git a/src/cases/wolf-ecs/frag_iter.js b/src/cases/wolf-ecs/frag_iter.js index 136a387..767ae45 100644 --- a/src/cases/wolf-ecs/frag_iter.js +++ b/src/cases/wolf-ecs/frag_iter.js @@ -1,35 +1,35 @@ -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() - for (let i = 0; i < 26; i++) { - ecs.defineComponent(i.toString(), types.u8); + for(let i = 0; i < 26; i++) { + ecs.defineComponent(i.toString(), types.u8) } - ecs.defineComponent("data", types.u32); + ecs.defineComponent("data", types.u32) - const q = ecs.createQuery("data"); + const q = ecs.createQuery("data") function sys() { - const data = ecs.components.data; - for (let i = 0, l = q.archetypes.length; i < l; i++) { - const arch = q.archetypes[i].entities; - for (let i = 0, l = arch.length; i < l; i++) { - data[arch[i]] *= 2; + const data = ecs.components.data + for(let i = 0, l = q.archetypes.length; i < l; i++) { + const arch = q.archetypes[i].entities + for(let i = 0, l = arch.length; i < l; i++) { + data[arch[i]] *= 2 } } } - for (let i = 0; i < n; i++) { - for (let i = 0; i < 26; i++) { - const id = ecs.createEntity(); - ecs.addComponent(id, i.toString()); - ecs.addComponent(id, "data"); - ecs.components.data[id] = 1; + for(let i = 0; i < n; i++) { + for(let i = 0; i < 26; i++) { + const id = ecs.createEntity() + ecs.addComponent(id, i.toString()) + ecs.addComponent(id, "data") + ecs.components.data[id] = 1 } } return () => { - sys(); - }; + sys() + } } diff --git a/src/cases/wolf-ecs/packed_1.js b/src/cases/wolf-ecs/packed_1.js index d13534e..e3aabc1 100644 --- a/src/cases/wolf-ecs/packed_1.js +++ b/src/cases/wolf-ecs/packed_1.js @@ -1,41 +1,41 @@ -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() - ecs.defineComponent("A", types.u32); - ecs.defineComponent("B", types.u32); - ecs.defineComponent("C", types.u32); - ecs.defineComponent("D", types.u32); - ecs.defineComponent("E", types.u32); + ecs.defineComponent("A", types.u32) + ecs.defineComponent("B", types.u32) + ecs.defineComponent("C", types.u32) + ecs.defineComponent("D", types.u32) + ecs.defineComponent("E", types.u32) - const q = ecs.createQuery("A"); + const q = ecs.createQuery("A") function sys() { - const A = ecs.components.A; - for (let i = 0, l = q.archetypes.length; i < l; i++) { - const arch = q.archetypes[i].entities; - for (let j = 0, l = arch.length; j < l; j++) { - A[arch[j]] *= 2; + const A = ecs.components.A + for(let i = 0, l = q.archetypes.length; i < l; i++) { + const arch = q.archetypes[i].entities + for(let j = 0, l = arch.length; j < l; j++) { + A[arch[j]] *= 2 } } } - for (let i = 0; i < n; i++) { - ecs.createEntity(); - ecs.addComponent(i, "A"); - ecs.components.A[i] = 1; - ecs.addComponent(i, "B"); - ecs.components.B[i] = 1; - ecs.addComponent(i, "C"); - ecs.components.C[i] = 1; - ecs.addComponent(i, "D"); - ecs.components.D[i] = 1; - ecs.addComponent(i, "E"); - ecs.components.E[i] = 1; + for(let i = 0; i < n; i++) { + ecs.createEntity() + ecs.addComponent(i, "A") + ecs.components.A[i] = 1 + ecs.addComponent(i, "B") + ecs.components.B[i] = 1 + ecs.addComponent(i, "C") + ecs.components.C[i] = 1 + ecs.addComponent(i, "D") + ecs.components.D[i] = 1 + ecs.addComponent(i, "E") + ecs.components.E[i] = 1 } return () => { - sys(); - }; + sys() + } } diff --git a/src/cases/wolf-ecs/packed_5.js b/src/cases/wolf-ecs/packed_5.js index dcbe113..36223eb 100644 --- a/src/cases/wolf-ecs/packed_5.js +++ b/src/cases/wolf-ecs/packed_5.js @@ -1,89 +1,89 @@ -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() - ecs.defineComponent("A", types.u32); - ecs.defineComponent("B", types.u32); - ecs.defineComponent("C", types.u32); - ecs.defineComponent("D", types.u32); - ecs.defineComponent("E", types.u32); + ecs.defineComponent("A", types.u32) + ecs.defineComponent("B", types.u32) + ecs.defineComponent("C", types.u32) + ecs.defineComponent("D", types.u32) + ecs.defineComponent("E", types.u32) - const qA = ecs.createQuery("A"); - const qB = ecs.createQuery("B"); - const qC = ecs.createQuery("C"); - const qD = ecs.createQuery("D"); - const qE = ecs.createQuery("E"); + const qA = ecs.createQuery("A") + const qB = ecs.createQuery("B") + const qC = ecs.createQuery("C") + const qD = ecs.createQuery("D") + const qE = ecs.createQuery("E") function sysA() { - const A = ecs.components.A; - for (let i = 0, l = qA.archetypes.length; i < l; i++) { - const arch = qA.archetypes[i].entities; - for (let j = 0, l = arch.length; j < l; j++) { - A[arch[j]] *= 2; + const A = ecs.components.A + for(let i = 0, l = qA.archetypes.length; i < l; i++) { + const arch = qA.archetypes[i].entities + for(let j = 0, l = arch.length; j < l; j++) { + A[arch[j]] *= 2 } } } function sysB() { - const B = ecs.components.B; - for (let i = 0, l = qB.archetypes.length; i < l; i++) { - const arch = qB.archetypes[i].entities; - for (let j = 0, l = arch.length; j < l; j++) { - B[arch[j]] *= 2; + const B = ecs.components.B + for(let i = 0, l = qB.archetypes.length; i < l; i++) { + const arch = qB.archetypes[i].entities + for(let j = 0, l = arch.length; j < l; j++) { + B[arch[j]] *= 2 } } } function sysC() { - const C = ecs.components.C; - for (let i = 0, l = qC.archetypes.length; i < l; i++) { - const arch = qC.archetypes[i].entities; - for (let j = 0, l = arch.length; j < l; j++) { - C[arch[j]] *= 2; + const C = ecs.components.C + for(let i = 0, l = qC.archetypes.length; i < l; i++) { + const arch = qC.archetypes[i].entities + for(let j = 0, l = arch.length; j < l; j++) { + C[arch[j]] *= 2 } } } function sysD() { - const D = ecs.components.D; - for (let i = 0, l = qD.archetypes.length; i < l; i++) { - const arch = qD.archetypes[i].entities; - for (let j = 0, l = arch.length; j < l; j++) { - D[arch[j]] *= 2; + const D = ecs.components.D + for(let i = 0, l = qD.archetypes.length; i < l; i++) { + const arch = qD.archetypes[i].entities + for(let j = 0, l = arch.length; j < l; j++) { + D[arch[j]] *= 2 } } } function sysE() { - const E = ecs.components.E; - for (let i = 0, l = qE.archetypes.length; i < l; i++) { - const arch = qE.archetypes[i].entities; - for (let j = 0, l = arch.length; j < l; j++) { - E[arch[j]] *= 2; + const E = ecs.components.E + for(let i = 0, l = qE.archetypes.length; i < l; i++) { + const arch = qE.archetypes[i].entities + for(let j = 0, l = arch.length; j < l; j++) { + E[arch[j]] *= 2 } } } - for (let i = 0; i < n; i++) { - ecs.createEntity(); - ecs.addComponent(i, "A"); - ecs.components.A[i] = 1; - ecs.addComponent(i, "B"); - ecs.components.B[i] = 1; - ecs.addComponent(i, "C"); - ecs.components.C[i] = 1; - ecs.addComponent(i, "D"); - ecs.components.D[i] = 1; - ecs.addComponent(i, "E"); - ecs.components.E[i] = 1; + for(let i = 0; i < n; i++) { + ecs.createEntity() + ecs.addComponent(i, "A") + ecs.components.A[i] = 1 + ecs.addComponent(i, "B") + ecs.components.B[i] = 1 + ecs.addComponent(i, "C") + ecs.components.C[i] = 1 + ecs.addComponent(i, "D") + ecs.components.D[i] = 1 + ecs.addComponent(i, "E") + ecs.components.E[i] = 1 } return () => { - sysA(); - sysB(); - sysC(); - sysD(); - sysE(); - }; + sysA() + sysB() + sysC() + sysD() + sysE() + } } diff --git a/src/cases/wolf-ecs/simple_iter.js b/src/cases/wolf-ecs/simple_iter.js index 1425cef..84a5906 100644 --- a/src/cases/wolf-ecs/simple_iter.js +++ b/src/cases/wolf-ecs/simple_iter.js @@ -1,83 +1,83 @@ -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() - ecs.defineComponent("A", types.u32); - ecs.defineComponent("B", types.u32); - ecs.defineComponent("C", types.u32); - ecs.defineComponent("D", types.u32); - ecs.defineComponent("E", types.u32); + ecs.defineComponent("A", types.u32) + ecs.defineComponent("B", types.u32) + ecs.defineComponent("C", types.u32) + ecs.defineComponent("D", types.u32) + ecs.defineComponent("E", types.u32) - const qAB = ecs.createQuery("A", "B"); - const qCD = ecs.createQuery("C", "D"); - const qCE = ecs.createQuery("C", "E"); + const qAB = ecs.createQuery("A", "B") + const qCD = ecs.createQuery("C", "D") + const qCE = ecs.createQuery("C", "E") function sysAB() { - const A = ecs.components.A; - const B = ecs.components.B; - for (let i = 0, l = qAB.archetypes.length; i < l; i++) { - const arch = qAB.archetypes[i].entities; - for (let i = 0, l = arch.length; i < l; i++) { - const temp = A[arch[i]]; - A[arch[i]] = B[arch[i]]; - B[arch[i]] = temp; + const A = ecs.components.A + const B = ecs.components.B + for(let i = 0, l = qAB.archetypes.length; i < l; i++) { + const arch = qAB.archetypes[i].entities + for(let i = 0, l = arch.length; i < l; i++) { + const temp = A[arch[i]] + A[arch[i]] = B[arch[i]] + B[arch[i]] = temp } } } function sysCD() { - const C = ecs.components.C; - const D = ecs.components.D; - for (let i = 0, l = qCD.archetypes.length; i < l; i++) { - const arch = qCD.archetypes[i].entities; - for (let i = 0, l = arch.length; i < l; i++) { - const temp = C[arch[i]]; - C[arch[i]] = D[arch[i]]; - D[arch[i]] = temp; + const C = ecs.components.C + const D = ecs.components.D + for(let i = 0, l = qCD.archetypes.length; i < l; i++) { + const arch = qCD.archetypes[i].entities + for(let i = 0, l = arch.length; i < l; i++) { + const temp = C[arch[i]] + C[arch[i]] = D[arch[i]] + D[arch[i]] = temp } } } function sysCE() { - const C = ecs.components.C; - const E = ecs.components.E; - for (let i = 0, l = qCE.archetypes.length; i < l; i++) { - const arch = qCE.archetypes[i].entities; - for (let i = 0, l = arch.length; i < l; i++) { - const temp = C[arch[i]]; - C[arch[i]] = E[arch[i]]; - E[arch[i]] = temp; + const C = ecs.components.C + const E = ecs.components.E + for(let i = 0, l = qCE.archetypes.length; i < l; i++) { + const arch = qCE.archetypes[i].entities + for(let i = 0, l = arch.length; i < l; i++) { + const temp = C[arch[i]] + C[arch[i]] = E[arch[i]] + E[arch[i]] = temp } } } - for (let i = 0; i < n; i++) { - const ab = ecs.createEntity(); - ecs.addComponent(ab, "A"); - ecs.addComponent(ab, "B"); + for(let i = 0; i < n; i++) { + const ab = ecs.createEntity() + ecs.addComponent(ab, "A") + ecs.addComponent(ab, "B") - const abc = ecs.createEntity(); - ecs.addComponent(abc, "A"); - ecs.addComponent(abc, "B"); - ecs.addComponent(abc, "C"); + const abc = ecs.createEntity() + ecs.addComponent(abc, "A") + ecs.addComponent(abc, "B") + ecs.addComponent(abc, "C") - const abcd = ecs.createEntity(); - ecs.addComponent(abcd, "A"); - ecs.addComponent(abcd, "B"); - ecs.addComponent(abcd, "C"); - ecs.addComponent(abcd, "D"); + const abcd = ecs.createEntity() + ecs.addComponent(abcd, "A") + ecs.addComponent(abcd, "B") + ecs.addComponent(abcd, "C") + ecs.addComponent(abcd, "D") - const abce = ecs.createEntity(); - ecs.addComponent(abce, "A"); - ecs.addComponent(abce, "B"); - ecs.addComponent(abce, "C"); - ecs.addComponent(abce, "E"); + const abce = ecs.createEntity() + ecs.addComponent(abce, "A") + ecs.addComponent(abce, "B") + ecs.addComponent(abce, "C") + ecs.addComponent(abce, "E") } return () => { - sysAB(); - sysCD(); - sysCE(); - }; + sysAB() + sysCD() + sysCE() + } } From 6f856c76b3cf0652bf4208f624e492a654d6caec Mon Sep 17 00:00:00 2001 From: EnderShadow8 <69184571+EnderShadow8@users.noreply.github.com> Date: Wed, 9 Jun 2021 17:22:13 +0800 Subject: [PATCH 6/8] Fix cases --- src/cases/wolf-ecs/add_remove.js | 10 ++++++---- src/cases/wolf-ecs/entity_cycle.js | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cases/wolf-ecs/add_remove.js b/src/cases/wolf-ecs/add_remove.js index 659e83f..0200f7a 100644 --- a/src/cases/wolf-ecs/add_remove.js +++ b/src/cases/wolf-ecs/add_remove.js @@ -11,16 +11,18 @@ export default function(n) { function add() { for(let i = 0, l = qA.archetypes.length; i < l; i++) { - for(let j of qA.archetypes[i].entities) { - ecs.addComponent(j, "B") + const ent = qA.archetypes[i].entities + for(let j = ent.length; j > 0; j--) { + ecs.addComponent(ent[j - 1], "B") } } } function remove() { for(let i = 0, l = qB.archetypes.length; i < l; i++) { - for(let j of qB.archetypes[i].entities) { - ecs.removeComponent(j, "B") + const ent = qB.archetypes[i].entities + for(let j = ent.length; j > 0; j--) { + ecs.removeComponent(ent[j - 1], "B") } } } diff --git a/src/cases/wolf-ecs/entity_cycle.js b/src/cases/wolf-ecs/entity_cycle.js index 9d1647f..8e69738 100644 --- a/src/cases/wolf-ecs/entity_cycle.js +++ b/src/cases/wolf-ecs/entity_cycle.js @@ -22,8 +22,9 @@ export default function(n) { function destroy() { for(let i = 0, l = qB.archetypes.length; i < l; i++) { - for(let j of qB.archetypes[i].entities) { - ecs.destroyEntity(j) + const ent = qB.archetypes[i].entities + for(let j = ent.length; j > 0; j--) { + ecs.destroyEntity(ent[j - 1]) } } } From 274db3a7e33d782aa5daf6d8b2faccab7dfa28d0 Mon Sep 17 00:00:00 2001 From: EnderShadow8 Date: Fri, 6 Aug 2021 11:21:32 +0800 Subject: [PATCH 7/8] WolfECS 2.0.0 --- README.md | 32 ++++++------ package-lock.json | 8 +-- src/cases/wolf-ecs/add_remove.js | 32 ++++++------ src/cases/wolf-ecs/entity_cycle.js | 26 +++++----- src/cases/wolf-ecs/frag_iter.js | 18 +++---- src/cases/wolf-ecs/packed_1.js | 39 +++++++-------- src/cases/wolf-ecs/packed_5.js | 69 ++++++++++++++------------ src/cases/wolf-ecs/simple_iter.js | 78 +++++++++++++++--------------- 8 files changed, 157 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index a8eb097..8d4364f 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,22 @@ A suite of benchmarks designed to test and compare JavaScript ECS library performance across a variety of challenging circumstances. -| | packed_1 | packed_5 | simple_iter | frag_iter | entity_cycle | add_remove | -| ----------- | -----------: | -----------: | -----------: | -----------: | -----------: | ----------: | -| becsy | 31,365 op/s | 36,042 op/s | 20,042 op/s | 59,558 op/s | 218 op/s | 8,308 op/s | -| bitecs | 235,089 op/s | 207,659 op/s | 115,812 op/s | 451,724 op/s | 1,302 op/s | 4,457 op/s | -| ecsy | 12,589 op/s | 7,537 op/s | 4,609 op/s | 24,726 op/s | 35 op/s | 846 op/s | -| flock-ecs | 3,312 op/s | 3,145 op/s | 1,738 op/s | 7,470 op/s | 94 op/s | 18,144 op/s | -| geotic | 37,355 op/s | 41,713 op/s | 26,426 op/s | 45,248 op/s | 27 op/s | 822 op/s | -| goodluck | 51,630 op/s | 53,048 op/s | 28,136 op/s | 100,559 op/s | 12,679 op/s | 89,410 op/s | -| javelin-ecs | 68,278 op/s | 68,148 op/s | 42,285 op/s | 118,208 op/s | 326 op/s | 3,479 op/s | -| makr | 14,031 op/s | 10,264 op/s | 7,241 op/s | 27,371 op/s | 10,812 op/s | 27,231 op/s | -| perform-ecs | 56,882 op/s | 58,701 op/s | 77,554 op/s | 31,243 op/s | 35 op/s | 314 op/s | -| picoes | 26,502 op/s | 7,274 op/s | 4,518 op/s | 15,414 op/s | 1,372 op/s | 4,061 op/s | -| tiny-ecs | 19,935 op/s | 17,047 op/s | 29,792 op/s | 50,206 op/s | 45 op/s | 1,010 op/s | -| wolf-ecs | 313,292 op/s | 279,654 op/s | 156,069 op/s | 529,318 op/s | 5,256 op/s | 23,150 op/s | - -The best result for each benchmark is marked in bold text. Note that run to run variance for these benchmarks is typically 1-4%. Any benchmarks within a few percent of each other should be considered “effectively equal”. The above benchmarks are run on node v16.3.0. +| | packed_1 | packed_5 | simple_iter | frag_iter | entity_cycle | add_remove | +| --- | --: |--: |--: |--: |--: |--: | +| becsy | 25,255 op/s | 24,249 op/s | 17,427 op/s | 45,495 op/s | 637 op/s | 3,847 op/s | +| bitecs | 76,780 op/s | 68,638 op/s | 35,408 op/s | 141,930 op/s | 254 op/s | 1,066 op/s | +| ecsy | 1,827 op/s | 1,902 op/s | 992 op/s | 5,538 op/s | 10 op/s | 216 op/s | +| flock-ecs | 715 op/s | 1,085 op/s | 466 op/s | 2,154 op/s | 48 op/s | 5,940 op/s | +| geotic | 8,665 op/s | 11,208 op/s | 4,587 op/s | 11,834 op/s | 6 op/s | 265 op/s | +| goodluck | 12,528 op/s | 14,476 op/s | 9,711 op/s | 28,465 op/s | 3,635 op/s | 26,686 op/s | +| javelin-ecs | TODO | TODO | TODO | TODO | TODO | TODO | +| makr | 3,907 op/s | 3,274 op/s | 2,307 op/s | 8,483 op/s | 3,529 op/s | 8,545 op/s | +| perform-ecs | 16,865 op/s | 14,345 op/s | 25,181 op/s | 8,150 op/s | 11 op/s | 65 op/s | +| picoes | 6,981 op/s | 1,912 op/s | 1,188 op/s | 4,288 op/s | 493 op/s | 1,386 op/s | +| tiny-ecs | 5,359 op/s | 5,318 op/s | 10,208 op/s | 16,305 op/s | 14 op/s | 291 op/s | +| wolf-ecs | 88,996 op/s | 104,250 op/s | 55,283 op/s | 195,988 op/s | 1,070 op/s | 3,146 op/s | + +The best result for each benchmark is marked in bold text. Note that run to run variance for these benchmarks is typically 1-4%. Any benchmarks within a few percent of each other should be considered “effectively equal”. The above benchmarks are run on node v15.12.0. ## Frameworks diff --git a/package-lock.json b/package-lock.json index a4dfa36..7ae1686 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "ecsy": "^0.4.2", "flock-ecs": "^0.1.5", "geotic": "^4.1.6", - "goodluck": "^7.0.0", + "goodluck": "^5.2.0", "makr": "^2.1.1", "perform-ecs": "^0.7.8", "picoes": "^1.0.0", @@ -74,9 +74,9 @@ } }, "node_modules/goodluck": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/goodluck/-/goodluck-7.0.0.tgz", - "integrity": "sha512-ml0lMI5CGXkSHRg7Po3wpyNm0qMDshrquiXEVFdAYyehvh8qT5SsQuLvK+T6YjUMJE27d1EkqVhNBp1ufsZEZA==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/goodluck/-/goodluck-5.2.0.tgz", + "integrity": "sha512-DzPuYxSuVObwbpyjKMYbMRucfcn6pt8HQSLEU5zPEp7twN6C7LlhUdOBVQTd48WHCCBgSH+WJr8XO8Pxc2JCyQ==", "engines": { "node": ">=12.0.0" } diff --git a/src/cases/wolf-ecs/add_remove.js b/src/cases/wolf-ecs/add_remove.js index 0200f7a..36fc3ab 100644 --- a/src/cases/wolf-ecs/add_remove.js +++ b/src/cases/wolf-ecs/add_remove.js @@ -3,35 +3,39 @@ import {ECS, types} from "wolf-ecs" export default function(n) { const ecs = new ECS() - ecs.defineComponent("A", types.u32) - ecs.defineComponent("B", types.u32) - - const qA = ecs.createQuery("A") - const qB = ecs.createQuery("B") + const A = ecs.defineComponent() + const B = ecs.defineComponent() + const qA = ecs.createQuery(A) function add() { - for(let i = 0, l = qA.archetypes.length; i < l; i++) { - const ent = qA.archetypes[i].entities - for(let j = ent.length; j > 0; j--) { - ecs.addComponent(ent[j - 1], "B") + const lB = B + for(let i = 0; i < qA.archetypes.length; i++) { + const arch = qA.archetypes[i].entities + for(let j = arch.length - 1; j >= 0; j--) { + ecs.addComponent(arch[j], lB) } } } + const qB = ecs.createQuery(B) function remove() { - for(let i = 0, l = qB.archetypes.length; i < l; i++) { - const ent = qB.archetypes[i].entities - for(let j = ent.length; j > 0; j--) { - ecs.removeComponent(ent[j - 1], "B") + const lB = B + for(let i = 0; i < qB.archetypes.length; i++) { + const arch = qB.archetypes[i].entities + 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") + ecs.addComponent(i, A) } + add() + remove() + return () => { add() remove() diff --git a/src/cases/wolf-ecs/entity_cycle.js b/src/cases/wolf-ecs/entity_cycle.js index 8e69738..0c94043 100644 --- a/src/cases/wolf-ecs/entity_cycle.js +++ b/src/cases/wolf-ecs/entity_cycle.js @@ -3,36 +3,36 @@ import {ECS, types} from "wolf-ecs" export default function(n) { const ecs = new ECS() - ecs.defineComponent("A") - ecs.defineComponent("B") - - const qA = ecs.createQuery("A") - const qB = ecs.createQuery("B") + const A = ecs.defineComponent() + const B = ecs.defineComponent() + const qA = ecs.createQuery(A) function create() { + const lB = B for(let i = 0, l = qA.archetypes.length; i < l; i++) { - for(let j = 0, l = qA.archetypes[i].entities.length; j < l; j++) { + const arch = qA.archetypes[i].entities + for(let j = 0, l = arch.length; j < l; j++) { const id = ecs.createEntity() - ecs.addComponent(id, "B") + ecs.addComponent(id, lB) const id2 = ecs.createEntity() - ecs.addComponent(id2, "B") + ecs.addComponent(id2, lB) } } } + const qB = ecs.createQuery(B) function destroy() { for(let i = 0, l = qB.archetypes.length; i < l; i++) { - const ent = qB.archetypes[i].entities - for(let j = ent.length; j > 0; j--) { - ecs.destroyEntity(ent[j - 1]) + const arch = qB.archetypes[i].entities + 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") - ecs.components.A[i] = 1 + ecs.addComponent(i, A) } create() diff --git a/src/cases/wolf-ecs/frag_iter.js b/src/cases/wolf-ecs/frag_iter.js index 767ae45..b6a6d04 100644 --- a/src/cases/wolf-ecs/frag_iter.js +++ b/src/cases/wolf-ecs/frag_iter.js @@ -3,19 +3,19 @@ import {ECS, types} from "wolf-ecs" export default function(n) { const ecs = new ECS() + const cmps = [] for(let i = 0; i < 26; i++) { - ecs.defineComponent(i.toString(), types.u8) + cmps.push(ecs.defineComponent()) } - ecs.defineComponent("data", types.u32) - - const q = ecs.createQuery("data") + const data = ecs.defineComponent(types.u32) + const q = ecs.createQuery(data) function sys() { - const data = ecs.components.data + const lData = data for(let i = 0, l = q.archetypes.length; i < l; i++) { const arch = q.archetypes[i].entities for(let i = 0, l = arch.length; i < l; i++) { - data[arch[i]] *= 2 + lData[i] *= 2 } } } @@ -23,9 +23,9 @@ export default function(n) { for(let i = 0; i < n; i++) { for(let i = 0; i < 26; i++) { const id = ecs.createEntity() - ecs.addComponent(id, i.toString()) - ecs.addComponent(id, "data") - ecs.components.data[id] = 1 + ecs.addComponent(id, cmps[i]) + ecs.addComponent(id, data) + data[id] = 1 } } diff --git a/src/cases/wolf-ecs/packed_1.js b/src/cases/wolf-ecs/packed_1.js index e3aabc1..89d6ab7 100644 --- a/src/cases/wolf-ecs/packed_1.js +++ b/src/cases/wolf-ecs/packed_1.js @@ -3,38 +3,39 @@ import {ECS, types} from "wolf-ecs" export default function(n) { const ecs = new ECS() - ecs.defineComponent("A", types.u32) - ecs.defineComponent("B", types.u32) - ecs.defineComponent("C", types.u32) - ecs.defineComponent("D", types.u32) - ecs.defineComponent("E", types.u32) - - const q = ecs.createQuery("A") + 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) function sys() { - const A = ecs.components.A + const lA = A for(let i = 0, l = q.archetypes.length; i < l; i++) { const arch = q.archetypes[i].entities for(let j = 0, l = arch.length; j < l; j++) { - A[arch[j]] *= 2 + lA[arch[j]] *= 2 } } } for(let i = 0; i < n; i++) { ecs.createEntity() - ecs.addComponent(i, "A") - ecs.components.A[i] = 1 - ecs.addComponent(i, "B") - ecs.components.B[i] = 1 - ecs.addComponent(i, "C") - ecs.components.C[i] = 1 - ecs.addComponent(i, "D") - ecs.components.D[i] = 1 - ecs.addComponent(i, "E") - ecs.components.E[i] = 1 + 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 } + sys() + return () => { sys() } diff --git a/src/cases/wolf-ecs/packed_5.js b/src/cases/wolf-ecs/packed_5.js index 36223eb..e736d38 100644 --- a/src/cases/wolf-ecs/packed_5.js +++ b/src/cases/wolf-ecs/packed_5.js @@ -3,80 +3,87 @@ import {ECS, types} from "wolf-ecs" export default function(n) { const ecs = new ECS() - ecs.defineComponent("A", types.u32) - ecs.defineComponent("B", types.u32) - ecs.defineComponent("C", types.u32) - ecs.defineComponent("D", types.u32) - ecs.defineComponent("E", types.u32) - - const qA = ecs.createQuery("A") - const qB = ecs.createQuery("B") - const qC = ecs.createQuery("C") - const qD = ecs.createQuery("D") - const qE = ecs.createQuery("E") + 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) function sysA() { - const A = ecs.components.A + const lA = A for(let i = 0, l = qA.archetypes.length; i < l; i++) { const arch = qA.archetypes[i].entities for(let j = 0, l = arch.length; j < l; j++) { - A[arch[j]] *= 2 + lA[arch[j]] *= 2 } } } + const qB = ecs.createQuery(B) function sysB() { - const B = ecs.components.B + const lB = B for(let i = 0, l = qB.archetypes.length; i < l; i++) { const arch = qB.archetypes[i].entities for(let j = 0, l = arch.length; j < l; j++) { - B[arch[j]] *= 2 + lB[arch[j]] *= 2 } } } + const qC = ecs.createQuery(C) function sysC() { - const C = ecs.components.C + const lC = C for(let i = 0, l = qC.archetypes.length; i < l; i++) { const arch = qC.archetypes[i].entities for(let j = 0, l = arch.length; j < l; j++) { - C[arch[j]] *= 2 + lC[arch[j]] *= 2 } } } + const qD = ecs.createQuery(D) function sysD() { - const D = ecs.components.D + const lD = D for(let i = 0, l = qD.archetypes.length; i < l; i++) { const arch = qD.archetypes[i].entities for(let j = 0, l = arch.length; j < l; j++) { - D[arch[j]] *= 2 + lD[arch[j]] *= 2 } } } + const qE = ecs.createQuery(E) function sysE() { - const E = ecs.components.E + const lE = E for(let i = 0, l = qE.archetypes.length; i < l; i++) { const arch = qE.archetypes[i].entities for(let j = 0, l = arch.length; j < l; j++) { - E[arch[j]] *= 2 + lE[arch[j]] *= 2 } } } for(let i = 0; i < n; i++) { ecs.createEntity() - ecs.addComponent(i, "A") - ecs.components.A[i] = 1 - ecs.addComponent(i, "B") - ecs.components.B[i] = 1 - ecs.addComponent(i, "C") - ecs.components.C[i] = 1 - ecs.addComponent(i, "D") - ecs.components.D[i] = 1 - ecs.addComponent(i, "E") - ecs.components.E[i] = 1 + 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 < 1000; i++) { + sysA() + sysB() + sysC() + sysD() + sysE() } return () => { diff --git a/src/cases/wolf-ecs/simple_iter.js b/src/cases/wolf-ecs/simple_iter.js index 84a5906..1185ae2 100644 --- a/src/cases/wolf-ecs/simple_iter.js +++ b/src/cases/wolf-ecs/simple_iter.js @@ -3,76 +3,76 @@ import {ECS, types} from "wolf-ecs" export default function(n) { const ecs = new ECS() - ecs.defineComponent("A", types.u32) - ecs.defineComponent("B", types.u32) - ecs.defineComponent("C", types.u32) - ecs.defineComponent("D", types.u32) - ecs.defineComponent("E", 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 qAB = ecs.createQuery("A", "B") - const qCD = ecs.createQuery("C", "D") - const qCE = ecs.createQuery("C", "E") + const qAB = ecs.createQuery(A, B) + const qCD = ecs.createQuery(C, D) + const qCE = ecs.createQuery(C, E) function sysAB() { - const A = ecs.components.A - const B = ecs.components.B + const lA = A + const lB = B for(let i = 0, l = qAB.archetypes.length; i < l; i++) { const arch = qAB.archetypes[i].entities - for(let i = 0, l = arch.length; i < l; i++) { - const temp = A[arch[i]] - A[arch[i]] = B[arch[i]] - B[arch[i]] = temp + for(let j = 0, l = arch.length; j < l; j++) { + const temp = lA[arch[j]] + lA[arch[j]] = lB[arch[j]] + lB[arch[j]] = temp } } } function sysCD() { - const C = ecs.components.C - const D = ecs.components.D + const lC = C + const lD = D for(let i = 0, l = qCD.archetypes.length; i < l; i++) { const arch = qCD.archetypes[i].entities - for(let i = 0, l = arch.length; i < l; i++) { - const temp = C[arch[i]] - C[arch[i]] = D[arch[i]] - D[arch[i]] = temp + for(let j = 0, l = arch.length; j < l; j++) { + const temp = lC[arch[j]] + lC[arch[j]] = lD[arch[j]] + lD[arch[j]] = temp } } } function sysCE() { - const C = ecs.components.C - const E = ecs.components.E + const lC = C + const lE = E for(let i = 0, l = qCE.archetypes.length; i < l; i++) { const arch = qCE.archetypes[i].entities - for(let i = 0, l = arch.length; i < l; i++) { - const temp = C[arch[i]] - C[arch[i]] = E[arch[i]] - E[arch[i]] = temp + for(let j = 0, l = arch.length; j < l; j++) { + const temp = lC[arch[j]] + lC[arch[j]] = lE[arch[j]] + lE[arch[j]] = temp } } } for(let i = 0; i < n; i++) { const ab = ecs.createEntity() - ecs.addComponent(ab, "A") - ecs.addComponent(ab, "B") + ecs.addComponent(ab, A) + ecs.addComponent(ab, B) const abc = ecs.createEntity() - ecs.addComponent(abc, "A") - ecs.addComponent(abc, "B") - ecs.addComponent(abc, "C") + ecs.addComponent(abc, A) + ecs.addComponent(abc, B) + ecs.addComponent(abc, C) const abcd = ecs.createEntity() - ecs.addComponent(abcd, "A") - ecs.addComponent(abcd, "B") - ecs.addComponent(abcd, "C") - ecs.addComponent(abcd, "D") + ecs.addComponent(abcd, A) + ecs.addComponent(abcd, B) + ecs.addComponent(abcd, C) + ecs.addComponent(abcd, D) const abce = ecs.createEntity() - ecs.addComponent(abce, "A") - ecs.addComponent(abce, "B") - ecs.addComponent(abce, "C") - ecs.addComponent(abce, "E") + ecs.addComponent(abce, A) + ecs.addComponent(abce, B) + ecs.addComponent(abce, C) + ecs.addComponent(abce, E) } return () => { From 585bfcfc3e3169db2365a8ead41adc77520696a6 Mon Sep 17 00:00:00 2001 From: EnderShadow8 Date: Sat, 29 Jan 2022 21:48:12 +0800 Subject: [PATCH 8/8] Add query_stress benchmark --- package-lock.json | 20 ++--- package.json | 2 +- src/bench.js | 25 ++++--- src/cases/wolf-ecs/add_remove.js | 49 ++++++------- src/cases/wolf-ecs/entity_cycle.js | 53 +++++++------- src/cases/wolf-ecs/frag_iter.js | 14 ++-- src/cases/wolf-ecs/packed_1.js | 56 +++++++------- src/cases/wolf-ecs/packed_5.js | 112 ++++++++++++++-------------- src/cases/wolf-ecs/query_stress.js | 86 ++++++++++++++++++++++ src/cases/wolf-ecs/simple_iter.js | 114 ++++++++++++++--------------- 10 files changed, 306 insertions(+), 225 deletions(-) create mode 100644 src/cases/wolf-ecs/query_stress.js diff --git a/package-lock.json b/package-lock.json index 82064d1..1772ad4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,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", @@ -71,9 +71,9 @@ } }, "node_modules/goodluck": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/goodluck/-/goodluck-5.2.0.tgz", - "integrity": "sha512-DzPuYxSuVObwbpyjKMYbMRucfcn6pt8HQSLEU5zPEp7twN6C7LlhUdOBVQTd48WHCCBgSH+WJr8XO8Pxc2JCyQ==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/goodluck/-/goodluck-7.0.0.tgz", + "integrity": "sha512-ml0lMI5CGXkSHRg7Po3wpyNm0qMDshrquiXEVFdAYyehvh8qT5SsQuLvK+T6YjUMJE27d1EkqVhNBp1ufsZEZA==", "engines": { "node": ">=12.0.0" } @@ -140,9 +140,9 @@ "integrity": "sha512-oPwSibOqllZeBu6U2v/wkqIq/XSiwaf0bff1aJhuPEBOqRWuo8iH/RP+bzPPUDdwQ6vRljIkksy0plmEIfbc3w==" }, "node_modules/wolf-ecs": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-2.1.1.tgz", - "integrity": "sha512-Wxdvv7hiJQdbRmfv/plm8xSPRyRg4dPkwajVEZf1mjt4ctumLAdZcvc4LIkFCvhLEABrX/KgTgpA5ucUGymahw==" + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-2.1.3.tgz", + "integrity": "sha512-zTmUsc85VrvFWi7BtZGgF2ZVtcohtMEeSC3fQrWVOENDJkXEm380EFsthr6tFWRJACFLWkw0zUCR6aBFuyTq+A==" } }, "dependencies": { @@ -241,9 +241,9 @@ "integrity": "sha512-oPwSibOqllZeBu6U2v/wkqIq/XSiwaf0bff1aJhuPEBOqRWuo8iH/RP+bzPPUDdwQ6vRljIkksy0plmEIfbc3w==" }, "wolf-ecs": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-2.1.1.tgz", - "integrity": "sha512-Wxdvv7hiJQdbRmfv/plm8xSPRyRg4dPkwajVEZf1mjt4ctumLAdZcvc4LIkFCvhLEABrX/KgTgpA5ucUGymahw==" + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/wolf-ecs/-/wolf-ecs-2.1.3.tgz", + "integrity": "sha512-zTmUsc85VrvFWi7BtZGgF2ZVtcohtMEeSC3fQrWVOENDJkXEm380EFsthr6tFWRJACFLWkw0zUCR6aBFuyTq+A==" } } } diff --git a/package.json b/package.json index fd4e0bc..f4be90c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/bench.js b/src/bench.js index 6ea28af..34ecf69 100644 --- a/src/bench.js +++ b/src/bench.js @@ -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", ]; @@ -26,6 +26,7 @@ const BENCHMARKS = { frag_iter: 100, entity_cycle: 1_000, add_remove: 1_000, + query_stress: 100, }; let libraries = []; diff --git a/src/cases/wolf-ecs/add_remove.js b/src/cases/wolf-ecs/add_remove.js index b343450..e0eb078 100644 --- a/src/cases/wolf-ecs/add_remove.js +++ b/src/cases/wolf-ecs/add_remove.js @@ -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.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) + 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.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 < 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(); + }; } diff --git a/src/cases/wolf-ecs/entity_cycle.js b/src/cases/wolf-ecs/entity_cycle.js index a6dbada..1c754c8 100644 --- a/src/cases/wolf-ecs/entity_cycle.js +++ b/src/cases/wolf-ecs/entity_cycle.js @@ -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.a.length; i < l; i++) { + const arch = qA.a[i].e; + 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.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 < 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(); + }; } diff --git a/src/cases/wolf-ecs/frag_iter.js b/src/cases/wolf-ecs/frag_iter.js index 25d313e..a583ff3 100644 --- a/src/cases/wolf-ecs/frag_iter.js +++ b/src/cases/wolf-ecs/frag_iter.js @@ -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 = []; @@ -13,8 +13,8 @@ export default function(n) { const dataQuery = ecs.createQuery(data); function dataSystem() { - for (let i = 0, l = dataQuery.length; i < l; i++) { - const arch = dataQuery[i]; + 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++) { data[arch[j]] *= 2; } @@ -23,8 +23,8 @@ export default function(n) { const zQuery = ecs.createQuery(z); function zSystem() { - for (let i = 0, l = zQuery.length; i < l; i++) { - const arch = zQuery[i]; + 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++) { z[arch[j]] *= 2; } @@ -45,4 +45,4 @@ export default function(n) { dataSystem(); zSystem(); }; -}; +} diff --git a/src/cases/wolf-ecs/packed_1.js b/src/cases/wolf-ecs/packed_1.js index f0f49fc..04720cf 100644 --- a/src/cases/wolf-ecs/packed_1.js +++ b/src/cases/wolf-ecs/packed_1.js @@ -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.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 < 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(); + }; } diff --git a/src/cases/wolf-ecs/packed_5.js b/src/cases/wolf-ecs/packed_5.js index 25ad92d..76d9649 100644 --- a/src/cases/wolf-ecs/packed_5.js +++ b/src/cases/wolf-ecs/packed_5.js @@ -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.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) + 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.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) + 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.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) + 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.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) + 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.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 < 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(); + }; } diff --git a/src/cases/wolf-ecs/query_stress.js b/src/cases/wolf-ecs/query_stress.js new file mode 100644 index 0000000..ac58359 --- /dev/null +++ b/src/cases/wolf-ecs/query_stress.js @@ -0,0 +1,86 @@ +import { ECS, types } from "wolf-ecs"; + +export default function (n) { + const ecs = new ECS(n * 200); + + const cmps = []; + for (let i = 0; i < 7; i++) { + cmps.push(ecs.defineComponent(types.u32)); + } + + const qA = ecs.createQuery(cmps[0]); + const qBC = ecs.createQuery(cmps[1], cmps[2]); + const qBCD = ecs.createQuery(cmps[1], cmps[2], cmps[3]); + const qDEFG = ecs.createQuery(cmps[3], cmps[4], cmps[5], cmps[6]); + + function sysA() { + const lA = cmps[0]; + 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; + } + } + } + + function sysBC() { + const lB = cmps[1]; + const lC = cmps[2]; + for (let i = 0, l = qBC.a.length; i < l; i++) { + const arch = qBC.a[i].e; + for (let j = 0, l = arch.length; j < l; j++) { + lB[arch[j]] *= 2; + lC[arch[j]] *= 2; + } + } + } + + function sysBCD() { + const lB = cmps[1]; + const lC = cmps[2]; + const lD = cmps[3]; + for (let i = 0, l = qBCD.a.length; i < l; i++) { + const arch = qBCD.a[i].e; + for (let j = 0, l = arch.length; j < l; j++) { + lB[arch[j]] *= 2; + lC[arch[j]] *= 2; + lD[arch[j]] *= 2; + } + } + } + + function sysDEFG() { + const lD = cmps[3]; + const lE = cmps[4]; + const lF = cmps[5]; + const lG = cmps[6]; + for (let i = 0, l = qDEFG.a.length; i < l; i++) { + const arch = qDEFG.a[i].e; + for (let j = 0, l = arch.length; j < l; j++) { + lD[arch[j]] *= 2; + lE[arch[j]] *= 2; + lF[arch[j]] *= 2; + lG[arch[j]] *= 2; + } + } + } + + for (let _ = 0; _ < n; _++) { + for (let i = 0; i < 128; i++) { + let e = ecs.createEntity(); + for (let j = 0; j < 7; j++) { + if (i & (1 << j)) { + // Create entities with every possible component combination (n * 2 ^ 7 ents in total) + ecs.addComponent(e, cmps[j]); + } + } + } + } + + return () => { + sysA(); + sysBC(); + sysBCD(); + sysDEFG(); + }; +} diff --git a/src/cases/wolf-ecs/simple_iter.js b/src/cases/wolf-ecs/simple_iter.js index c46a211..46e8ba9 100644 --- a/src/cases/wolf-ecs/simple_iter.js +++ b/src/cases/wolf-ecs/simple_iter.js @@ -1,83 +1,83 @@ -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 qAB = ecs.createQuery(A, B) - const qCD = ecs.createQuery(C, D) - const qCE = ecs.createQuery(C, E) + const qAB = ecs.createQuery(A, B); + const qCD = ecs.createQuery(C, D); + const qCE = ecs.createQuery(C, E); function sysAB() { - const lA = A - const lB = B - for(let i = 0, l = qAB.length; i < l; i++) { - const arch = qAB[i] - for(let j = 0, l = arch.length; j < l; j++) { - const temp = lA[arch[j]] - lA[arch[j]] = lB[arch[j]] - lB[arch[j]] = temp + const lA = A; + const lB = B; + for (let i = 0, l = qAB.a.length; i < l; i++) { + const arch = qAB.a[i].e; + for (let j = 0, l = arch.length; j < l; j++) { + const temp = lA[arch[j]]; + lA[arch[j]] = lB[arch[j]]; + lB[arch[j]] = temp; } } } function sysCD() { - const lC = C - const lD = D - for(let i = 0, l = qCD.length; i < l; i++) { - const arch = qCD[i] - for(let j = 0, l = arch.length; j < l; j++) { - const temp = lC[arch[j]] - lC[arch[j]] = lD[arch[j]] - lD[arch[j]] = temp + const lC = C; + const lD = D; + for (let i = 0, l = qCD.a.length; i < l; i++) { + const arch = qCD.a[i].e; + for (let j = 0, l = arch.length; j < l; j++) { + const temp = lC[arch[j]]; + lC[arch[j]] = lD[arch[j]]; + lD[arch[j]] = temp; } } } function sysCE() { - const lC = C - const lE = E - for(let i = 0, l = qCE.length; i < l; i++) { - const arch = qCE[i] - for(let j = 0, l = arch.length; j < l; j++) { - const temp = lC[arch[j]] - lC[arch[j]] = lE[arch[j]] - lE[arch[j]] = temp + const lC = C; + const lE = E; + for (let i = 0, l = qCE.a.length; i < l; i++) { + const arch = qCE.a[i].e; + for (let j = 0, l = arch.length; j < l; j++) { + const temp = lC[arch[j]]; + lC[arch[j]] = lE[arch[j]]; + lE[arch[j]] = temp; } } } - for(let i = 0; i < n; i++) { - const ab = ecs.createEntity() - ecs.addComponent(ab, A) - ecs.addComponent(ab, B) + for (let i = 0; i < n; i++) { + const ab = ecs.createEntity(); + ecs.addComponent(ab, A); + ecs.addComponent(ab, B); - const abc = ecs.createEntity() - ecs.addComponent(abc, A) - ecs.addComponent(abc, B) - ecs.addComponent(abc, C) + const abc = ecs.createEntity(); + ecs.addComponent(abc, A); + ecs.addComponent(abc, B); + ecs.addComponent(abc, C); - const abcd = ecs.createEntity() - ecs.addComponent(abcd, A) - ecs.addComponent(abcd, B) - ecs.addComponent(abcd, C) - ecs.addComponent(abcd, D) + const abcd = ecs.createEntity(); + ecs.addComponent(abcd, A); + ecs.addComponent(abcd, B); + ecs.addComponent(abcd, C); + ecs.addComponent(abcd, D); - const abce = ecs.createEntity() - ecs.addComponent(abce, A) - ecs.addComponent(abce, B) - ecs.addComponent(abce, C) - ecs.addComponent(abce, E) + const abce = ecs.createEntity(); + ecs.addComponent(abce, A); + ecs.addComponent(abce, B); + ecs.addComponent(abce, C); + ecs.addComponent(abce, E); } return () => { - sysAB() - sysCD() - sysCE() - } + sysAB(); + sysCD(); + sysCE(); + }; }