Skip to content

Node can go 3x faster #2

@Skitionek

Description

@Skitionek

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions