Typed array iteration

JavaScript performance comparison

Revision 6 of this test case created by vjeux

Info

Added Canvas

Preparation code

<canvas width="10" height="50" id="canvas"></canvas>
<script>
  var classic = new Array(2000);
  var canvas = document.getElementById("canvas").getContext("2d").getImageData(0, 0, 10, 50).data; // 50 * 10 * 4 = 2000
  var unfixed = new Uint8Array();
  var fixed = new Uint8Array(2000);
  for (var i = 0; i < 2000; ++i) {
   var number = ~~ (Math.random() * 200)
   classic[i] = number;
   canvas[i] = number;
   unfixed[i] = number;
   fixed[i] = number;
  }
</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 < 2000; ++ii) {
 classic[ii] += 1;
}
pending…
Canvas
for (var ii = 0; ii < 2000; ++ii) {
 canvas[ii] += 1;
}
pending…
Unfixed
for (var ii = 0; ii < 2000; ++ii) {
 unfixed[ii] += 1;
}
pending…
Fixed
for (var ii = 0; ii < 2000; ++ii) {
 fixed[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