本文介绍了Firefox使用asm.js配置文件似乎没有更快,但Chrome是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我从asm.js网站上下了一个小函数。我使用模块模式来封装它:一次为asm,一次使用相同的语法,但没有使用asm注释,一次像香草-javascript一样。 var add_asm =(function MyAOTMod(stdlib,foreign,heap){use asm; var sqrt = stdlib.Math.sqrt; $ b $ (x,y){x = + x; // x的类型为double y = + y; // y的类型为double return + sqrt(square(x)+ square(y)); }; }(窗口)); var add_reg_asmstyle =(function MyAsmLikeRegularMod(){ function square(x){x = + x; return +(x * x) ; } 返回函数(x,y){x = + x; // x的类型是double y = + y; // y的类型是double 返回+ Math.sqrt(square(x)+ square(y)); }; }()); $ b $ add_reg =(function MyStrictProfile(){use strict; return function(x,y){ return Math.sqrt (x * x + y * y); }; }()) 我创建了一个小的jsperf: jsperf代码与上面的代码略有不同,它包含了以下讨论线索中的提示 jsperf.com/asm-simple/7\">http://jsperf.com/asm-simple/7 性能表明firefox 22是最慢的是asm-syntax(有或没有use asm注解),chrome是asm-mode中最快的。所以我的问题是:这是怎么回事可能?我希望Firefox在asm模式下速度最快。我不希望看到铬的差异。我使用错误的asm语法?我错过了什么? 任何建议或澄清是非常感激。感谢您在Firefox中运行代码时,您可以经常看到asm.js调用的速度大幅度下降,这是很可能是由重复编译(在控制台中可见)或由js到asm调用的成本造成的。这个假设通过 Luke Wagner ,asm.js的实现者: 我们已经知道的一个性能故障会导致人们尝试基准测试。 js是从非asm.js调用到 asm.js,反之亦然,由于通用进入/退出例程,比正常调用慢得多。我们计划在接下来的几个月内解决这个问题,但同时,为了基准测试的目的,试着把保存在一个单独的asm.js模块中,不需要调用出去。 亲自看看 - 看小提琴: http://jsperf.com/asm-simple/10 Firefox 26:asm-asm中的 22,600K 操作数/秒与asm-js中的 300 (!)大小写。 Chrome 28:18K vs 13K IE11:对于所有的测试来说都是7.5K,没有太大的差别,除了死代码消除之外,它在这里发光;) / li> I am trying to understand how exactly ASM works and when it kicks in.I took a small function from the asm.js website. I wrap it using the module pattern: once for asm, once with the same syntax but without the "use asm" annotation, and once like vanilla-javascript. var add_asm = (function MyAOTMod(stdlib, foreign, heap) { "use asm"; var sqrt = stdlib.Math.sqrt; function square(x) { x = +x; return +(x * x); } return function(x, y) { x = +x; // x has type double y = +y; // y has type double return +sqrt(square(x) + square(y)); };}(window));var add_reg_asmstyle = (function MyAsmLikeRegularMod() { function square(x) { x = +x; return +(x * x); } return function(x, y) { x = +x; // x has type double y = +y; // y has type double return +Math.sqrt(square(x) + square(y)); };}());var add_reg = (function MyStrictProfile() { "use strict"; return function(x, y) { return Math.sqrt(x * x + y * y); };}())I created a small jsperf:the jsperf code is slightly different from the above, incorporating tips from the discussion thread belowhttp://jsperf.com/asm-simple/7The performance shows that firefox 22 is slowest with the asm-syntax (with or without the "use asm" annotation), and chrome is fastest in asm-mode.So my question is: how is this possible? I would expect Firefox to be fastest in asm mode. I would not expect to see a difference for Chrome. Do I use a wrong asm syntax? What am I missing?Any advice or clarification is greatly appreciated. Thanks, 解决方案 When you run code in Firefox, you can often see huge drop in speed for asm.js calls, which is most probably caused either by repeated compilation (which is visible in console) or by cost of js-to-asm calls. This hypothesis is further strenghtened by Luke Wagner, implementor of asm.js: one performance fault that we already know trips up people trying to benchmark asm.js is that calling from non-asm.js into asm.js and vice versa is much slower than normal calls due to general-purpose enter/exit routines. We plan to fix this in the next few months but, in the meantime, for benchmarking purposes, try to keep the whole computation happening inside a single asm.js module, not calling in and out.To see it for yourself - look at the fiddle: http://jsperf.com/asm-simple/10 Firefox 26: 22,600K ops/sec in asm-asm case vs 300(!) in asm-js case.Chrome 28: 18K vs 13KIE11: ~7.5K for all tests, no big difference observed, except for dead code ellimination, where it shines ;) 这篇关于Firefox使用asm.js配置文件似乎没有更快,但Chrome是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 09:09