Skip to content
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

Performance improvement #232

Open
veksa opened this issue Dec 4, 2023 · 2 comments
Open

Performance improvement #232

veksa opened this issue Dec 4, 2023 · 2 comments

Comments

@veksa
Copy link

veksa commented Dec 4, 2023

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
Copy link

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
Copy link
Author

veksa commented Dec 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants