tslib icon indicating copy to clipboard operation
tslib copied to clipboard

Performance improvement

Open veksa opened this issue 2 years ago • 2 comments

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

veksa avatar Dec 04 '23 09:12 veksa

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

HolgerJeromin avatar Dec 04 '23 10:12 HolgerJeromin

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.

veksa avatar Dec 04 '23 10:12 veksa