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 13K
- IE11: ~7.5K for all tests, no big difference observed, except for dead code ellimination, where it shines 😉