Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2853.0 Safari/537.36
Chrome 55
Linux
Other
8 years ago
Test name Executions per second
soa 2.2 Ops/sec
aos 1.6 Ops/sec
soa mark II 2.1 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 * 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;
    }
  • soa mark II

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