Created
April 25, 2013 18:32
-
-
Save hanksudo/5461982 to your computer and use it in GitHub Desktop.
Loop Performance - Cache Array Length,
Reference : http://taitems.github.io/Front-End-Development-Guidelines/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toLoop = new Array(1000); | |
for (var i = 0; i < toLoop.length; i++) { | |
// BAD - the length has to be evaluated 1000 times | |
} | |
for (var i = 0, len = toLoop.length; i < len; i++) { | |
// GOOD - the length is only looked up once and then cached | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment