asmjs

JavaScript performance comparison

Revision 6 of this test case created by Calvin Metcalf

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var withAsm = (function(stdlib) {
        "use asm";
        var pow = stdlib.Math.pow;
   
        function mandlebrot(cx, cy, maxIter) {
          cx = +cx;
          cy = +cy;
          maxIter = maxIter | 0;
          var iter = 0;
          var xn = 0.0;
          var x = 0.0;
          var y = 0.0;
          while (((pow(x, 2.0) + pow(y, 2.0)) < 4.0) & ((iter | 0) < (maxIter | 0))) {
            xn = +(pow(x, 2.0) - pow(y, 2.0) + cx);
            y = +((x * y) * 2.0 + cy);
            x = +xn;
            iter = (iter + 1) | 0;
          }
          return iter | 0;
        }
        return {
          mandlebrot: mandlebrot
        };
      }(window));
   
      var withoutAsm = (function(stdlib) {
        var pow = stdlib.Math.pow;
   
        function mandlebrot(cx, cy, maxIter) {
          cx = +cx;
          cy = +cy;
          maxIter = maxIter | 0;
          var iter = 0;
          var xn = 0.0;
          var x = 0.0;
          var y = 0.0;
          while (((pow(x, 2.0) + pow(y, 2.0)) < 4.0) & ((iter | 0) < (maxIter | 0))) {
            xn = +(pow(x, 2.0) - pow(y, 2.0) + cx);
            y = +((x * y) * 2.0 + cy);
            x = +xn;
            iter = (iter + 1) | 0;
          }
          return iter | 0;
        }
        return {
          mandlebrot: mandlebrot
        };
      }(window));
   
      var asm = new Function("stdlib", " \"use asm\";\n var pow = stdlib.Math.pow;\n\n function mandlebrot(cx, cy, maxIter) {\n    cx = +cx;\n     cy = +cy;\n     maxIter = maxIter|0;\n     var iter=0;\n     var xn= 0.0;\n     var x = 0.0;\n     var y = 0.0;\n     while ( ((pow(x,2.0) + pow(y,2.0)) < 4.0)&((iter|0) < (maxIter|0))) {\n         xn = +( pow(x,2.0) - pow(y,2.0) + cx);\n         y = +((x*y)*2.0 + cy);\n         x = +xn;\n         iter=(iter+1)|0;\n     }\n     \n     return iter|0;\n }\n return {\n mandlebrot: mandlebrot\n};");
   
      var noasm = new Function("stdlib", " var pow = stdlib.Math.pow;\n\n function mandlebrot(cx, cy, maxIter) {\n    cx = +cx;\n     cy = +cy;\n     maxIter = maxIter|0;\n     var iter=0;\n     var xn= 0.0;\n     var x = 0.0;\n     var y = 0.0;\n     while ( ((pow(x,2.0) + pow(y,2.0)) < 4.0)&((iter|0) < (maxIter|0))) {\n         xn = +( pow(x,2.0) - pow(y,2.0) + cx);\n         y = +((x*y)*2.0 + cy);\n         x = +xn;\n         iter=(iter+1)|0;\n     }\n     \n     return iter|0;\n }\n return {\n mandlebrot: mandlebrot\n};");
   
      var compiledWithAsm = asm(window),
          compiledWithoutAsm = noasm(window);
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
regular
withoutAsm.mandlebrot(0, 0, 500);
pending…
asm
withAsm.mandlebrot(0, 0, 500);
pending…
compiled regular
compiledWithoutAsm.mandlebrot(0, 0, 500);
pending…
compiled asm
compiledWithAsm.mandlebrot(0, 0, 500);
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