Loops (long array) (more accurate tests)
JavaScript performance comparison
Info
Creates the array with actual values and runs the result through a function to keep the browser from optimizing in weird ways or something maybe.
Please note that all loops consider the array unmodified during the loop itself while native methods such forEach are safer.
Preparation code
<script>
var arr = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3];
function doNothingWith(something) {
return something
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
while loop that imitates a for loop |
|
pending… |
while loop that imitates a for loop, caching the length |
|
pending… |
Reverse while loop |
|
pending… |
Reverse do … while loop |
|
pending… |
Reverse for loop |
|
pending… |
Old ’n’ busted for loop |
|
pending… |
Old ’n’ busted for loop, caching the length |
|
pending… |
Cool guy loop |
|
pending… |
Cool guy loop, caching the length |
|
pending… |
Native Array#forEach implementation |
|
pending… |
Native Array#forEach implementation with named function |
|
pending… |
Unrolled loop |
|
pending… |
Native Array#forEach |
|
pending… |
fully used for loop via --i |
|
pending… |
fully used for loop via i-- |
|
pending… |
fully used for loop via --i and call |
|
pending… |
Native Array#forEach with context |
|
pending… |
safer for loop (aka: forEach logic) |
|
pending… |
even safer for loop (aka: better forEach logic) |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Mathias Bynens and last updated
- Revision 2: published
- Revision 4: published by Thomas Aylott and last updated
- Revision 6: published by WebReflection and last updated
- Revision 9: published by JFSIII and last updated
- Revision 10: published by Thomas Aylott
- Revision 17: published
- Revision 18: published by Lockal
- Revision 19: published by Lockal
- Revision 20: published
- Revision 21: published
- Revision 22: published
- Revision 23: published by Mike Lee
- Revision 24: published
- Revision 26: published by match vs split
- Revision 27: published by John-David Dalton and last updated
- Revision 29: published by Lucas Cepeda
- Revision 30: published
- Revision 31: published
- Revision 32: published
- Revision 33: published
- Revision 34: published by FrancescoMM
- Revision 35: published by Elijah Manor
- Revision 38: published by D. S. Schneider
- Revision 39: published
- Revision 40: published
- Revision 41: published by D. S. Schneider
- Revision 42: published
- Revision 43: published
- Revision 44: published
- Revision 46: published
- Revision 47: published
- Revision 48: published by Justin Bangerter
- Revision 49: published by Conor Malone
- Revision 50: published by Conor Malone
- Revision 51: published by Tri
- Revision 52: published by Raul
- Revision 53: published
- Revision 54: published
- Revision 55: published
- Revision 56: published
- Revision 58: published
- Revision 59: published
- Revision 60: published
- Revision 61: published
- Revision 62: published
- Revision 63: published
- Revision 64: published
- Revision 66: published
- Revision 67: published
- Revision 68: published
- Revision 69: published
- Revision 70: published
- Revision 71: published
- Revision 72: published
- Revision 73: published by wfreytag
- Revision 75: published
- Revision 76: published
- Revision 77: published
- Revision 78: published
- Revision 79: published
- Revision 80: published
- Revision 81: published by eTagTechnologies.Inc
- Revision 82: published by JeanHuguesRobert
- Revision 83: published
- Revision 84: published by Simo
- Revision 85: published
- Revision 86: published by Matt
- Revision 87: published
0 comments