Fast Typed Arrays

JavaScript performance comparison

Test case created by Ben Vanik

Preparation code

<script>
  function fillArray(a, w, h) {
   var n = 0;
   for (var y = 0; y < h; y++) {
    for (var x = 0; x < w; x++) {
     a[n++] = x % 128 + 1;
     a[n++] = x % 128 + 2;
     a[n++] = x % 128 + 3;
     a[n++] = x % 128 + 4;
    }
   }
  };
  
  function fillArray2(a, w, h) {
   var n = 0;
   for (var y = 0; y < h; y++) {
    for (var x = 0; x < w; x++) {
     a[n++] = x % 128 + 1;
     a[n++] = x % 128 + 2;
     a[n++] = x % 128 + 3;
     a[n++] = x % 128 + 4;
    }
   }
  };
  
  function fillArrayJS(a, w, h) {
   var n = 0;
   for (var y = 0; y < h; y++) {
    for (var x = 0; x < w; x++) {
     a[n++] = x % 128 + 1;
     a[n++] = x % 128 + 2;
     a[n++] = x % 128 + 3;
     a[n++] = x % 128 + 4;
    }
   }
  };
  
  function fillArrayUint8(a, w, h) {
   var n = 0;
   for (var y = 0; y < h; y++) {
    for (var x = 0; x < w; x++) {
     a[n++] = x % 128 + 1;
     a[n++] = x % 128 + 2;
     a[n++] = x % 128 + 3;
     a[n++] = x % 128 + 4;
    }
   }
  };
  
  var s_jsarray = [];
  s_jsarray.length = 1024 * 1024 * 4;
  for (var n = 0; n < s_jsarray.length; n++) {
   s_jsarray[n] = 0;
  }
  var s_tyarray = new Uint8Array(1024 * 1024 * 4);
  
  var s_jsarray1 = [0, 0, 0, 0];
  var s_tyarray1 = new Uint8Array(4);
  fillArray(s_jsarray1, 1, 1);
  fillArray(s_tyarray1, 1, 1);
  fillArray2(s_tyarray1, 1, 1);
  fillArray2(s_jsarray1, 1, 1);
  fillArrayJS(s_jsarray1, 1, 1);
  fillArrayUint8(s_tyarray1, 1, 1);
</script>
    

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Polymorphic JS
fillArray(s_jsarray, 1024, 1024);
pending…
Polymorphic Typed
fillArray(s_tyarray, 1024, 1024);
pending…
Polymorphic JS Reversed
fillArray2(s_jsarray, 1024, 1024);
pending…
Polymorphic Typed Reversed
fillArray2(s_tyarray, 1024, 1024);
pending…
Monomorphic JS
fillArrayJS(s_jsarray, 1024, 1024);
pending…
Monomorphic Typed
fillArrayUint8(s_tyarray, 1024, 1024);
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.

0 Comments