Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Chrome 124
Mac OS X 10.15.7
Desktop
8 months ago
Test name Executions per second
soa 6.9 Ops/sec
aos 4.7 Ops/sec
Script Preparation code:
AخA
 
var x = [], y =[], z =[];
var vectors = [];
for(var i = 0; i < 1000000; i++){
  x[i] = Math.random()*100|0;
  y[i] = Math.random()*100|0;
  z[i] = Math.random()*100|0;
  
  vectors[i] = { x: x[i], y: y[i], z: z[i] };
}
var vector;
Tests:
  • soa

     
    for (var i = 0, li=x.length; i < li; ++i) {
        x[i] = 2 * x[i];
        y[i] = 2 * y[i];
        z[i] = 2 * z[i];
    }
  • aos

     
    for (var i = 0, li=vectors.length; i < li; ++i) {
        vector = vectors[i];
        vector.x = 2 * vector.x;
        vector.y = 2 * vector.y;
        vector.z = 2 * vector.z;
    }