Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Classes SoA vs AoS
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.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
SoA
3472144.0 Ops/sec
AoS
3482580.8 Ops/sec
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; }