我已经创建了一个jsPref来测试这个asm.js的东西:http://jsperf.com/asm-diag
我认为我做错了,因为asmjs代码的运行速度比常规js代码慢两倍,即使在每晚的firefox中也是如此.
我不知道代码中有什么问题.
提前致谢,
编辑:
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;
};
Run Code Online (Sandbox Code Playgroud)
ASM:
var _diag = diag(10, 100);
Run Code Online (Sandbox Code Playgroud)
定期:
var _diag = Math.sqrt(Math.pow(10, 2) + Math.pow(100, 2))
Run Code Online (Sandbox Code Playgroud)
调用asm.js函数形式JS时会产生很大的开销,而您正在进行基准测试的函数没有做足够的工作来弥补调用开销.
当您使用asm.js函数时,尝试最小化asm < - > JS通信并在asm.js模块中执行更大的工作.
jsperf强制asm.js模块在测试期间重新编译几次,但Firefox还不支持重新编译,因此jsperf测试永远不会在asm.js模式下运行.
| 归档时间: |
|
| 查看次数: |
822 次 |
| 最近记录: |