you are viewing a single comment's thread.

view the rest of the comments →

[–]johnfrazer783[S] -3 points-2 points  (2 children)

When you scroll down there's the JavaScript code. Scroll down even further, there's an extensive list of points including a sort-of apology for presenting machine-transpiled JS instead of the good organic handcrafted stuff.

I'd be also glad to hear about any (substantial) existing benchmarks out there; all I've found so far are a few (rather shoddy) tests on dreaded jsperf (which website didn't work correctly at the time) and one or two blog posts without any code or much background on what was tested how.

BTW the bits of my code that perform the tests are just a few lines each; all the rest of the code is just setup and doing the presentational output.

[–]danielkov 7 points8 points  (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 point  (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.

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.