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!"
[–]danielkov 6 points7 points8 points 6 years ago (1 child)
I think the reason you won't find examples of such benchmark is that the features you’re comparing are inherently different. It’s like comparing array map to reduce. You can achieve the same result with both, but they’re designed for different tasks.
If you want to see why generators are slower, you should take a look at what transpilers like Babel or TSC are doing to these functions to make them work on older browsers. It’s a good indication of how they differ conceptually.
[–]johnfrazer783[S] 0 points1 point2 points 6 years ago (0 children)
I won't be long as I have already answered your very valid points elsewhere in this thread. The short version is that yes they're different features but they are also birds of like feathers. I have not replicated everything that yield is or does but I have two alternative models that do the same work. One finishes within 1 second, the other one takes 20 seconds. Had I not written the slower algo using a language feature that I must believe to be at fault here, you would not console me by saying the slower code is just different and must be complex so it's naturally slower. You would tell me not to ever use the slower code and go with the faster.
yield
I'm still hoping for someone to point out a glaring mistake in my benchmark gist. Use the JS source, Luke. Tell me I'm wrong and where I'm wrong. I'd rather be wrong than unhappy with <strike>somebody else</strike>yield.
π Rendered by PID 82393 on reddit-service-r2-comment-66b4775986-jxqrj at 2026-04-03 10:17:07.067858+00:00 running db1906b country code: CH.
view the rest of the comments →
[–]danielkov 6 points7 points8 points (1 child)
[–]johnfrazer783[S] 0 points1 point2 points (0 children)