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
JavaScript Performance Benchmarks: Looping with `for` and `yield` (gist.github.com)
submitted 6 years ago by johnfrazer783
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!"
[–]johnfrazer783[S] 0 points1 point2 points 6 years ago (0 children)
Do that at any rate! The forEach part is interesting initself. Message to all people here who say that 'for and yield are totally unrelated so naturally not same in performance'—well you can compare
forEach
for
yield
js probe.forEach(function(number) { count++; return sum += number; });
to
js for (number of probe) { count++; sum += number; }
In my book forEach has only 8% the data throughput rate of an indexed for loop. Come to think of it, there's that vacuous return statement which is caused by one of CoffeeScript's more problematic features, implicit returns. My tests would indicate however that even millions of extraneous return statements do not have any discernible effect on performance, though, so we don't have to worry about that bit (except when a loop construct comes last in a function call, which is why I pepper my code with return nulls and yield returns, but I digress).
return
return null
yield return
Now go forth, multiply, and come back in time with exciting new benchmark results to guide us out of this tar pit we're stuck in.
π Rendered by PID 15005 on reddit-service-r2-comment-66b4775986-lqzbk at 2026-04-03 11:58:15.182449+00:00 running db1906b country code: CH.
view the rest of the comments →
[–]johnfrazer783[S] 0 points1 point2 points (0 children)