Created
September 16, 2010 15:31
-
-
Save lamberta/582623 to your computer and use it in GitHub Desktop.
JavaScript Loop Speed Tests
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
/* JavaScript Loop Speed Tests. | |
* 100,000,000 iterations, average of 10 runs. | |
* Run on Chromium 6.0.472.53 | |
*/ | |
/* Basic for-loop | |
* 1056.9 ms | |
*/ | |
for (var i=0; i < count; i++) { | |
1+1; | |
} | |
/* JSLint for-loop | |
* 1322.6 ms | |
*/ | |
for (var i=0; i < count; i += 1) { | |
1+1; | |
} | |
/* Reverse loop | |
* 1097.6 ms | |
*/ | |
while (count--) { | |
1+1; | |
} | |
/* Reverse loop, execute once | |
* 1123.3 ms | |
*/ | |
do { | |
1+1; | |
} while (count--); | |
/* While loop that imitates a for-loop | |
* 1368.9 ms | |
*/ | |
var i=0; | |
while (i < count) { | |
1+1; | |
i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment