5 ms·
You probably implemented it in a wrong way. On my machine, a JSFiddle version is 3.5x faster, while in your benchmark, it is 1.4x faster.
by IvanK_net 5y ago
You probably implemented it in a wrong way. On my machine, a JSFiddle version is 3.5x faster, while in your benchmark, it is 1.4x faster.
- deleted 5y ago[deleted]
- tambourine_man 5y agoCan you post a link to your version?
- brrrrrm 5y agoYour fiddle doesn’t seem to run a warmup or the code more than once. I’m guessing the second loop (the unrolled one) benefits from some JIT warmup. That being said, I’m seeing a very similar relative difference in your fiddle to what I see in the benchmark I posted.
- eyelidlessness 5y ago> JIT warmup No kidding, this can be seriously misleading. IMO JS (and likely many other JIT VM) benchmarks should run: - multiple cold starts - multiple pre-warmed starts (essentially run your bench twice, discard the results, run it again) - isolated cases - shared runtime cases with evenly distributed ordering All of those will reveal different performance characteristics you may want to know about, and people evaluating your results should be able to know about. Cold starts are a worst case scenario of each implementation, warmed should show a more ideal outcome. Isolated will again highlight the perf of each implementation on its own merits, whereas shared runtime should help highlight how interacting with other real-world code affects VM optimization of that implementation.
- xpl 5y agoYeah, properly benchmarking JS code is hard because of how complex is the V8's optimizing compiler infrastructure. I once made an online tool for measuring run times of JS code, with [hopefully, lol] proper warmup and protection against possible dead code elimination optimization. There are a few clickable benchmark examples in the readme: https://github.com/xpl/what-code-is-faster#what-code-is-faster https://github.com/xpl/what-code-is-faster#what-code-is-fast...
- ignoramous 5y ago> No kidding, this can be seriously misleading. Reminds me of prof. Emery Berger's talk, Performance Matters: https://www.youtube-nocookie.com/embed/r-TLSBdHe1A https://www.youtube-nocookie.com/embed/r-TLSBdHe1A
- IvanK_net 5y agoIf a 50-character piece of JS is running for two seconds, it was definitely optimized at some point. And even a most advanced optimization of 50 characters would not take more than 0.1 seconds. Even with a warmup, the unwrapped version is more than 3x faster.
- brrrrrm 5y agohttps://jsbenchit.org/?src=cb64%2CeJztV21v2zYQ_iuEPyVIRvNIHl-S9UPRrdvQpSuQtRvQFIXsKIhQWQpspVsT5L_voewkkmWn3bC3Am0_WOGRx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4D2SQs8eYwn42w_NLW__m2fnPz5uYPDir1Ng%3D%3D https://jsbenchit.org/?src=cb64%2CeJztV21v2zYQ_iuEPyVIRvNIHl...
- ShamelessC 5y ago> You probably implemented it in a wrong way. That's pretty opaquely rude, just FYI.