-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: use native Array methods instead of for loop #3519
Conversation
It was unfair. At least for var array = new Array(1000); which generates an array with only holes will never call the callback function array.some(x => !x) // => false Besides, the two tests generates different results because they do different things. In my benchmark, We use Array methods not because they are fast, but because they are easier to write and result in cleaner code. For library uses, I do think plain for loop are better for performance reasons. |
thats weird.
I dont think so. |
Basically, simpler code tends to benefit more from optimization by the engines. |
Maybe yes for other cases. But for Because I don't think browsers can do lots of things for it. There is no silver bullet. Note |
I got similar results with |
@CarterLi Indeed, you are right that this change lowers performance. |
see
https://www.measurethat.net/Benchmarks/Show/9251/0/array-every-vs-some-vs-for-loop-fork
https://www.measurethat.net/Benchmarks/Show/11704/0/for-loop-vs-arraysome