我创建了一个 jsPref,来测试这个 asm.js 的东西:http://jsperf.com/asm-diag http://jsperf.com/asm-diag
我想我做错了什么,因为asmjs代码的运行速度比常规js代码慢两倍,即使在firefox nightly中也是如此。
我不知道代码有什么问题。
提前致谢,
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))
-
从 JS 调用 asm.js 函数时会产生很大的开销,并且您正在基准测试的函数没有做足够的工作来弥补调用开销。
当您使用 asm.js 函数时,请尝试最小化 asmJS 通信并在 asm.js 模块中完成更大的工作块。
-
jsperf 在测试过程中强制 asm.js 模块重新编译多次,但 Firefox 尚不支持重新编译,因此 jsperf 测试永远不会在 asm.js 模式下运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)