asm.js math on integers

JavaScript performance comparison

Revision 10 of this test case created by and last updated

Preparation code

<script>
// data
var makeIntArray = function (n, min, max) {
   return Array(n).join('.').split('.').map(function (v) {
     return (Math.random()*(max - min))|0 + min;
   });
};
var dataIn = makeIntArray(2<<12, 120000, 150000);
var dataOut = 1;


// code
var normal = function (a,b,c) {
  return (a - b + c)|0;
};

var strict = function (a,b,c) {

  'use strict';
  return (a - b + c)|0;
};

var asm = (function MyAsmModule (stdlib, foreign, heap) {

    "use asm";
    function fun (a,b,c) {
            a = a|0;  
            b = b|0;
            c = c|0;
            return (a - b + c)|0;
    } ;

    return {
        fun: fun
   };
}(window, {}, new Uint32Array(2<<12)));

var asm_0 = function (a,b,c) {
  a = a|0;  
  b = b|0;
  c = c|0;
  return (a - b + c)|0;
};

var runner = function (fn, data) {
   var r = 1;
   for (var l = data.length-1, i = 0; i < l; ++i) {
      r = fn(r, data[i], data[i+1]);
   }

   return r;
};

var runner_dead_code = function (fn, data) {
   var r = 1, _null ;
   for (var l = data.length, i = 0; i < l-1; ++i) {
      _null = fn(r, data[i], data[i+1]);
   }

   return r;
};

var asm_runner = (function AsmWithRunner (stdlib, foreign, heap) {

    "use asm";
    
    function fun (a,b,c) {
            a = a|0;  
            b = b|0;
            c = c|0;
            return (a - b + c)|0;
    };
    function run (i, l) {
            i = i|0;
            l = l|0;          
            var r = 1;
           
            for (i = 0, l = 8191; i < l; ++i) {
               r = fun(r, heap[i], heap[i+1])|0;
            }
            return r;
    };


    return {
        fun: fun,
        run: run
   };
}(window, {}, new Uint32Array(dataIn) ));

</script>
      
<script>
Benchmark.prototype.teardown = function() {
  document.title = dataOut;
  var dataOut = 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
asm from JS loop
dataOut = runner(asm.fun, dataIn);
pending…
asm from asm loop
dataOut = asm_runner.run();
pending…
asm (no pragma)
dataOut = runner(asm_0, dataIn);
pending…
strict mode
dataOut = runner(strict, dataIn);
pending…
dead code
dataOut = runner_dead_code(normal, dataIn);
pending…
normal js
dataOut = runner(normal, dataIn);
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.

1 Comment

oztro commented :

asm from JS loop firefox 23 bug??