Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Chrome 110
Windows
Desktop
one year ago
Test name Executions per second
soa 2.1 Ops/sec
aos 1.5 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;
    }