Created
November 4, 2011 14:46
-
-
Save devdazed/1339487 to your computer and use it in GitHub Desktop.
Interesting differences in loops and incrementers
This file contains 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 i = 0, n = 100000000, t = 0; | |
console.time('i++'); | |
for (; i < n; i++){ | |
t += 1; | |
} | |
console.timeEnd('i++'); | |
//i++: 147ms | |
i = 0; t = 0; | |
console.time('++i'); | |
for (; i < n; ++i){ | |
t += 1; | |
} | |
console.timeEnd('++i'); | |
//++i: 183ms | |
i = 0; t = 0; | |
console.time('i+=1'); | |
for (; i < n; i+=1){ | |
t += 1; | |
} | |
console.timeEnd('i+=1'); | |
//i+=1: 147ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
after 10,000 runs it holds consistent that all methods end up being the same at about 150ms