Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Created April 25, 2013 18:32
Show Gist options
  • Save hanksudo/5461982 to your computer and use it in GitHub Desktop.
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/
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