Created
June 29, 2014 18:29
-
-
Save chrislaughlin/b68baba50db63f2d9f40 to your computer and use it in GitHub Desktop.
Loop Performance
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 array = []; | |
for (var i = 0; i < 100; i++) { | |
array.push(i); | |
} | |
console.time('loop ++i'); | |
for(var i = 0; i < array.length; ++i) { | |
var a = array[i]; | |
} | |
console.timeEnd('loop ++i'); | |
console.time('loop i++'); | |
for(var i = 0; i < array.length; ++i) { | |
var a = array[i]; | |
} | |
console.timeEnd('loop i++'); | |
console.time('loop length var'); | |
for(var i = 0, length = array.length; i < length; i++) { | |
var a = array[i]; | |
} | |
console.timeEnd('loop length var'); | |
console.time('loop revrse'); | |
for(var i = array.length-1; i > 0; i--) { | |
var a = array[i]; | |
} | |
console.timeEnd('loop revrse'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment