for loop research
JavaScript performance comparison
Info
Varius for-loop variants: * with length caching * with various counter increment (++i, i++) * while alternative
Preparation code
<script>
Benchmark.prototype.setup = function() {
var arr = [];
for (var i=0; i<1000; i++) {
arr.push('arr-value-' + i);
}
function worker() {
return(1+1);
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
classic for-loop |
|
pending… |
++i |
|
pending… |
caching length in loop |
|
pending… |
caching length outside loop |
|
pending… |
double caching length |
|
pending… |
while alternative i-- |
|
pending… |
while alternative --i |
|
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
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 6: published
- Revision 8: published
- Revision 9: published
- Revision 15: published
- Revision 16: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published
- Revision 22: published
- Revision 23: published
0 comments