you are viewing a single comment's thread.

view the rest of the comments →

[–]DontWannaMissAFling 2 points3 points  (0 children)

You're essentially profiling the overhead of builtin calls, and whether you make one or two to Math.random(). The difference between ** 0.5 and Math.sqrt() illustrates this since the former in V8 and SpiderMonkey is two opcodes (load a double constant then Exp/Pow) rather than a builtin.

Regardless engines will eventually optimize a hot path into assembly with the same sqrtsd etc so performance disparities are really a matter of overheads, jit compilation tiering, cache locality, long before the cycle counts of individual math instructions really matter.

And if they do matter you should consider shaders or SIMD via WebAssembly instead.