4

我创建了一个 jsPref,来测试这个 asm.js 的东西:http: //jsperf.com/asm-diag

我认为我做错了什么,因为 asmjs 代码的运行速度比常规 js 代码慢两倍,即使在 firefox nightly 中也是如此。

我不知道代码有什么问题。

提前致谢,


编辑:

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;
};

汇编:

var _diag = diag(10, 100);

常规的:

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

2 回答 2

6
  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.

于 2013-06-06T01:31:06.623 回答
0

刚刚偶然发现了这个 asm.js 的东西——听起来很棒。我尝试稍微修改测试,以使两个测试中的情况在函数调用、属性查找等方面尽可能相似。http://jsperf.com/asm-diag/10

我想,需要一段更大的代码——繁重的数学是它可能擅长的地方。我将密切关注 asm.js 的开发。

于 2014-05-21T16:38:43.403 回答