For vs While
JavaScript performance comparison
Preparation code
<script>
var i, values = [],
sum = 0;
for (i = 0; i < 10000; i++) {
values[i] = i;
}
function add(val) {
sum += val;
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
ForEach |
|
pending… |
for loop, simple |
|
pending… |
for loop, cached length |
|
pending… |
for loop, reverse |
|
pending… |
for loop, cached length, no callback |
|
pending… |
for loop, cached length, using function.call and supplying index and original array |
|
pending… |
While, reversed + simple |
|
pending… |
While, reversed + callback |
|
pending… |
while reversed without explicit comparison |
|
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 Jon-Carlos Rivera
- Revision 2: published by Adrian Sutton
- Revision 3: published by Joshua Kehn
- Revision 8: published
- Revision 9: published
- Revision 10: published by Jonas Fischer
- Revision 12: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published by Shane Grüling
- Revision 19: published
- Revision 20: published by SourceR
- Revision 21: published by oHessling
- Revision 22: published by oHessling
- Revision 23: published by oHessling
- Revision 24: published by Raul
- Revision 25: published
- Revision 26: published by Henrique
- Revision 27: published
- Revision 28: published
- Revision 32: published
- Revision 33: published
- Revision 34: published
- Revision 35: published
- Revision 38: published
- Revision 39: published by JasonG
- Revision 40: published by Bunchofstring
- Revision 43: published by Jaybuz
- Revision 44: published
- Revision 49: published
- Revision 50: published
- Revision 52: published
- Revision 53: published
- Revision 54: published
- Revision 55: published
- Revision 56: published
- Revision 57: published
- Revision 58: published
- Revision 60: published by Ceane Lamerez
0 comments