microsoft / tslib

Runtime library for TypeScript helpers.
BSD Zero Clause License
1.26k stars 130 forks source link

Performance improvement #232

Open veksa opened 11 months ago

veksa commented 11 months ago

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

HolgerJeromin commented 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

veksa commented 11 months ago

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.