The Rusty Web: Targeting the Web with Rust
It looks like the slowdown on wasm is related to the powi call in the distance function (which the benchmark page mentions as a likely suspect). Emscripten currently compiles @llvm.powi into a JS Math.pow call, however this powi call is just being used to multiply a number by itself. I filed this issue:<p><pre><code>  https:&#x2F;&#x2F;github.com&#x2F;kripken&#x2F;emscripten-fastcomp&#x2F;issues&#x2F;171
</code></pre>
to track this issue in Emscripten.<p>In JS, the assumption is that code may be written by humans, so engines are expected to optimize things like Math.pow calls with small integer exponents implicitly, which is likely why this code is faster in JS. And in the asm.js case, the page mentions that it&#x27;s using &quot;almost asm&quot;, which is not actually asm.js, so it&#x27;s using the JS optimizations.<p>This is one of the characteristic differences between JS and WebAssembly: in WebAssembly, the compiler producing the code has a much bigger optimization role to play.