Open veksa opened 11 months ago
If we want to microbenchmark we could also do the even more performant version of your very simple test:
var sum = 0;
for (var v of Object.values(object)) {
}
But this has perhaps too bad browser support (no IE, no edge 12-13, no browser before 2016/2017): https://caniuse.com/object-values
I updated the benchmark at https://jsben.ch/IWqVX. Object.values performs significantly better, and to support incompatible browsers, we can write a polyfill function.
Based on the benchmark, the "for in" loop appears to be 10% slower than the "for" loop. Does it make sense to replace all instances of "for in"?
https://jsben.ch/kxBxv