Why is the asmjs code slower even in firefox?

只愿长相守 提交于 2019-12-10 16:09:33

问题


I've created a jsPref, to test this asm.js thing: http://jsperf.com/asm-diag

I think I did something wrong, because the asmjs code runs two times slower than the regular js code, even in firefox nightly.

I have no idea what's wrong in the code.

Thanks in advance,


Edit:

Benchmark.prototype.setup = function() {
  function DiagModule(stdlib, foreign, heap) {
      "use asm";

      // Variable Declarations
      var sqrt = stdlib.Math.sqrt;
      var pow = stdlib.Math.pow;

      // Function Declarations
      function square(x) {
          x = x|0;
          return (pow(x, 2))|0;
      }

      function diag(x, y) {
          x = x|0;
          y = y|0;
          return +sqrt(square(x) + square(y));
      }

      return { diag: diag };
  }

  diag = DiagModule({ Math: Math }).diag;
};

asm:

var _diag = diag(10, 100);

regular:

var _diag = Math.sqrt(Math.pow(10, 2) + Math.pow(100, 2))

回答1:


  1. There is a significant overhead when calling asm.js function form JS and the function you're benchmarking doesn't do enough work to make up for the calling overhead.

    When you use asm.js functions try to minimize asm<->JS communication and do bigger chunks of work in asm.js modules.

  2. jsperf forces asm.js module to be recompiled several times during the test, but Firefox doesn't support recompilation yet, so jsperf tests never run in asm.js mode.




回答2:


Just stumbled upon this asm.js thing - which sounds awesome. I made a stab at modifying the test slightly to make the situation in the two tests as similar as possible with regard to function calls, property lookup, etc. http://jsperf.com/asm-diag/10.

I guess, a bigger piece of code is needed - heavy math is where it would likely excel. I'm gonna follow asm.js development closely.



来源:https://stackoverflow.com/questions/16688187/why-is-the-asmjs-code-slower-even-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!