4 ms·
The old and famous jsperf.com is available under .app again. Here is a for/while comparison f.ex.: https://jsperf.app/doyeka/5 https://jsperf.app/doyeka/5
by Aldipower 10mo ago
The old and famous jsperf.com is available under .app again.
Here is a for/while comparison f.ex.:
https://jsperf.app/doyeka/5 https://jsperf.app/doyeka/5
- fainpul 10mo agoI tested Firefox, Safari and Brave on macOS. Results are totally different for each. "for loop, positive" seems to be the only safe bet. Safari was very slow on everything, Brave and Firefox were slow on `for … of`. I'm surprised by the huge variance. Can these results be trusted?
- ygra 10mo agoThe way the array is constructed at least leads to holey arrays in V8. Perhaps similar in other implementations. The performance characteristics between different array types may vary significantly as well. Still, the traditional for loop, counting upwards seems to be fastest for me across Chrome and Firefox on Linux. For-of is slowest by a wide margin.
- nitwit005 10mo agoThere is always going to be a big gap between a browser that had a particular optimization, and one where it is absent. But, browsers are an odd case where optimizations often prove not to be worth it on real world websites. The cost to optimize can easily exceed the savings.
- xlii 10mo agoOn Safari are results were within 3% of each other. On Brave "for loop, negative" was 84% faster than "for of". This small sample (2 browsers on macOS) align with my expectations of "Good luck optimizing JavaScript that has dozen of different implementations".