Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Classes SoA vs AoS
(version: 1)
Same as usual Float Array base SoA vs AoS but with classes and objects instead of raw number. I was cursious if the benefit of SoA still holds true even with classes.
Comparing performance of:
SoA vs AoS
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
'use strict'; window.N = Math.pow(10, 9); class PointAndVelocity { constructor(x, y, vx, vy) { this.x = x; this.y = y; this.vx = vx; this.vy = vy; } } class Point { constructor(x, y) { this.x = x; this.y = y; } } class Velocity { constructor(vx, vy) { this.vx = vx; this.vy = vy; } } aos = Array(N).fill(new PointAndVelocity(0, 0, 0, 0)) .map(() => new PointAndVelocity(Math.random() * 100, Math.random() * 100, Math.random() * 100, Math.random() * 100)); // SoA, we try to duplicate the data so numeric differences are out of the question. points = Array(N).fill(new Point(0, 0)). .map((_, i) => new Point(aos[i].x, aos[i].y)); velocities = Array(N).fill(new Velocity(0, 0)). .map((_, i) => new Velocity(aos[i].vx, aos[i].vy));
Tests:
SoA
var N = window.N; for (var i = 0; i < N; ++i) { var point = points[i]; var velocity = velocities[i]; point.x += velocity.vx; point.y += velocity.vy; }
AoS
var N = window.N; for (var i = 0; i < N; ++i) { var pav = aos[i] pav.x += pav.vx; pav.y += pav.vy; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
SoA
AoS
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
Browser/OS:
Chrome 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
SoA
9179404.0 Ops/sec
AoS
6634439.0 Ops/sec
Related benchmarks:
ES6 Class vs Prototype vs Object Literal access 2
Instantiation via ES6 Class vs Prototype vs Object Literal
ES6 Class vs Prototype vs Object Literal vs Object & Functions 2
ES6 Class vs Prototype vs Object Literal n moar
Comparison of classes vs prototypes vs object literals also including the inheritance
ES6 Class vs Prototype vs Object Literal v2 with Extends
ES6 Class vs Prototype vs Object Literal vs ES6 Class extends vs ES6 Class extends twice
ES6 Class vs Prototype vs Object Literal v2 with Extends v2
OOP-ish SoA vs AoS
Comments
Confirm delete:
Do you really want to delete benchmark?