Why is asmjs code slower even in Firefox?

I created jsPref to check this asm.js thing: http://jsperf.com/asm-diag

I think I did something wrong, because asmjs code is twice as slow as regular js code, even in firefox at night.

I do not know what is wrong in the code.

Thanks in advance,


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)) 
+4
source share
2 answers
  • When you call the form of the JS function asm.js, there is a significant overhead, and the function you are testing does not do enough work to compensate for the overhead.

    When you use the asm.js functions, try to minimize the asm ↔ JS connection and do big chunks of work in the asm.js modules.

  • jsperf forces the asm.js module to recompile several times during the test, but Firefox does not yet support recompilation, so jsperf tests never run in asm.js.

+6
source

Just stumbled upon this asm.js thing - which sounds amazing. I took a hit by slightly modifying the test to make the situation in the two tests as similar to function calls, property searches, etc. http://jsperf.com/asm-diag/10 .

I guess most of the code is required - heavy math - this is where it is likely to surpass. I will closely monitor the development of asm.js.

0
source

Source: https://habr.com/ru/post/1482118/


All Articles