Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Can JavaScript benefit from the ECS pattern 4
(version: 1)
Proper ECS pattern test with only one entity type, three components. Separate loops for ECS.
Comparing performance of:
OO-style vs ECS-style
Created:
9 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
class Point { constructor(x, y) { this.x = x; this.y = y; this.health = 100; } tick() { this.x += 2; this.y += 2; this.health -= 1; } } var pointClasses = []; var maxPoints = 1000000; class PointB { pointObjectsA = new Int32Array( maxPoints ); pointObjectsB = new Int32Array( maxPoints ); pointObjectsC = new Int32Array( maxPoints ); } var test = new PointB( ); for (let i = 0; i < maxPoints; i++) { pointClasses.push(new Point(0, 0)); test.pointObjectsA[ i ] = 0; test.pointObjectsB[ i ] = 0; test.pointObjectsC[ i ] = 100; }
Tests:
OO-style
let i; for ( i = 0; i < maxPoints; i++ ) pointClasses[ i ].tick();
ECS-style
let i; for ( i = 0; i < maxPoints; i++ ) { test.pointObjectsA[ i ] += 2; } for ( i = 0; i < maxPoints; i++ ) { test.pointObjectsB[ i ] += 2; } for ( i = 0; i < maxPoints; i++ ) { test.pointObjectsC[ i ] = 100; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
OO-style
ECS-style
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
OO-style
151.2 Ops/sec
ECS-style
507.8 Ops/sec
Related benchmarks:
literals vs classes
ES6 Class vs Prototype with longer chain vs Object Literal
ES6 Class vs Object Literal 100k runs
Hidden class test
ES6 Class vs Prototype vs Object Literal (fixed)
aefq4fghtdgf3d2w
ES6 Class vs Function with float32array vs Function with Array
ES6 Class vs Function with float32array vs Function with Array 2
Can JavaScript benefit from the ECS pattern 3
Comments
Confirm delete:
Do you really want to delete benchmark?