TypedArray vs. array[] vs. nested[][] (v4)

Revision 4 of this benchmark created on


Description

Read access speed for different array containers.

Setup

var W = 100;
var size = W * W;
var typed = new Int32Array(size);
crypto.getRandomValues(typed);
var array = [...typed];
var nested = [];
for (let n = 0; n < W; n++) {
  nested.push(
    [...typed.slice(n * W, (n + 1) * W)]
  );
}
var acc = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
TypedArray
for (let x = 0; x < size; x++) {
  acc += ++typed[x];
}
ready
array[]
for (let x = 0; x < size; x++) {
  acc += ++array[x];
}
ready
nested[][]
for (let y = 0; y < W; y++) {
  for (let x = 0; x < W; x++) {
    acc += ++nested[y][x];
  }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.