Closed lukeed closed 7 years ago
As strange as it may sound, as long as a len and i are eagerly defined, for-loops always outperform while-loops.
Looks like that's true in this case, but no, not always. I do benchmarks quite often, and I see while
loops outperform for
loops just as often. It also changes from time to time when optimizations are made in v8, so don't get to comfortable with your favorite :)
thanks for the pr!
Oh yeah, not sure why I said "always"
It happens a lot, but definitely not across the board.
Thanks! 🎉
Hey there,
As strange as it may sound, as long as a
len
andi
are eagerly defined,for-loops
always outperformwhile-loops
.I was going to release (yet another!) flatten lib, but then I saw that our implementations were nearly the same, so a PR makes more sense 😉
Here are the benchmarks from my machine --- ran a few times to verify: