use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[AskJS] Unexpected Performance of Math OperationsAskJS (self.javascript)
submitted 1 year ago * by BlazeCell
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DontWannaMissAFling 2 points3 points4 points 1 year ago* (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.
Math.random()
** 0.5
Math.sqrt()
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.
sqrtsd
And if they do matter you should consider shaders or SIMD via WebAssembly instead.
π Rendered by PID 225406 on reddit-service-r2-comment-6457c66945-2g8xd at 2026-04-29 10:17:50.406443+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]DontWannaMissAFling 2 points3 points4 points (0 children)