KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I was reading Nicholas Zackas' High Performance Javascript in which he discusses optimizing a for loop by reversing it and minimizing its property lookups. Instead of: for (var i = 0; i < items.length; i++ ) { processItems(items[i]); } You get: for (var i = items.length; i--; ) { processItems(items[i]); } At the time of writing, the execution times were " up to 50%-60% faster than the original ." Yet I created a jsperf and in Firefox and Chrome I've noticed that the optimized for loop is actually noticeably slower, especially in Firefox. Do newer browsers optimize for loops differently? Is the most efficient way to write a for loop now simply the basic way?
Tags (comma-separated)
Save Edits
Cancel