Run details:
Mozilla/5.0 (Linux; Android 13; SM-A515F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36
Chrome Mobile 112
Android
Mobile
one year ago
Test name Executions per second
soa 1.5 Ops/sec
aos 0.6 Ops/sec
soa mark II 1.0 Ops/sec
Script Preparation code:
x
 
var N = 1000000;
var x = [], y = [], z = [];
var xt = new Float32Array(1000000);
var yt = new Float32Array(1000000);
var zt = new Float32Array(1000000);
var vectors = [];
for(var i = 0; i < N; i++){
  x[i] = Math.random();
  y[i] = Math.random();
  z[i] = Math.random();
  
  xt[i] = x[i];
  yt[i] = y[i];
  zt[i] = z[i];
  
  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;
        y[i] *= 2;
        z[i] *= 2;
    }
  • aos

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

     
    for (var i = 0, li=xt.length; i < li; ++i) {
        xt[i] *= 2;
    }
    for (var i = 0, li=yt.length; i < li; ++i) {
        yt[i] *= 2;
    }
    for (var i = 0, li=zt.length; i < li; ++i) {
        zt[i] *= 2;
    }