-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
It might sound a bit like sorcery but if you will traverse array backwards you can achieve up to 3 times better performance. The only difference is to use this construction:
for ( var i = array.length; i--; ) {
(...)
}
There has been prolonged discussion about it on GitHub: https://stackoverflow.com/questions/5349425/whats-the-fastest-way-to-loop-through-an-array-in-javascript
and here you can find related test:
http://jsbench.github.io/#67b13d4e78cdd0d7a7346410d5becf12
I didn't check it in node though but in browser... :
https://jsbench.me/j0jw6pygqu/1
Also as you can see in tests you can gain performance on declaring the data type for array.
Wonder how much improvements can be gain in PHP and if running on node will make the difference.
Metadata
Metadata
Assignees
Labels
No labels