Typed array iteration

JavaScript performance comparison

Revision 33 of this test case created

Info

Array iteration

Preparation code

<canvas width="512" height="512" id="canvas" style="border: 1px dashed black;">
</canvas>
<script>
  var classic = new Array(256);
  for (var i = 0; i < 256; i++) {
    classic[i] = 0;
  }

  var context = document.getElementById("canvas").getContext("2d");
  var imageData = context.getImageData(0, 0, 256, 256);
  var canvas = imageData.data;
  if (typeof Uint8Array !== 'undefined') {
    var typed8 = new Uint8Array(256);
    var typed16 = new Uint16Array(256);
    var typed32 = new Uint32Array(256);
    var typedF32 = new Float32Array(256);
    var typedF64 = new Float64Array(256);
  }

  for (var i = 0; i < 256; ++i) {
    var number = ~~ (Math.random() * 254)
    classic[i] = number;
    canvas[i] = number;
    if (typeof Uint8Array !== 'undefined') {
      typed8[i] = number;
      typed16[i] = number;
      typed32[i] = number;
      typedF32 = number;
      typedF64 = number;
    }
  }

  context.putImageData(imageData, 0, 0);
</script>
<script>
Benchmark.prototype.setup = function() {
    if (typeof Uint8Array === 'undefined') {
      throw "Error";
    }
   
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Classic
for (var ii = 0; ii < 256; ++ii) {
  classic[ii] += 1;
}
pending…
Canvas
for (var ii = 0; ii < 256; ++ii) {
  canvas[ii] += 1;
}
pending…
Typed 8
for (var ii = 0; ii < 256; ++ii) {
  typed8[ii] += 1;
}
pending…
Typed 16
for (var ii = 0; ii < 256; ++ii) {
  typed16[ii] += 1;
}
pending…
Typed 32
for (var ii = 0; ii < 256; ++ii) {
  typed32[ii] += 1;
}
pending…
Typed F32
for (var ii = 0; ii < 256; ++ii) {
  typedF32[ii] += 1.0;
}
pending…
Typed F64
for (var ii = 0; ii < 256; ++ii) {
  typedF64[ii] += 1;
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment