Loop iteration (length comparison variations)
JavaScript performance comparison
Info
Comparison of different ways to treat the length of an array when iterating the array.
Preparation code
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
window.list = [];
var x = 100;
for (var y = 0; y < x; y++) {
window.list[y] = true;
}
};
Benchmark.prototype.teardown = function() {
delete window.list;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Using list.length |
|
pending… |
Using static len - outside for declr. |
|
pending… |
Using static len - inside for declr. |
|
pending… |
Reverse Loop (for) |
|
pending… |
Reverse Loop (while) |
|
pending… |
Reverse Loop (for) w/ outside declaration & -- |
|
pending… |
Reverse Loop (for) w/ outside declaration & >= 0 |
|
pending… |
Destructive array - shift |
|
pending… |
Destructive array - pop |
|
pending… |
Destructive array - pop w/ reverse |
|
pending… |
_.times |
|
pending… |
_.each |
|
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 5: published
- Revision 6: published by Vance Ingalls
- Revision 7: published
- Revision 8: published by Vance Ingalls
- Revision 9: published by Raymond
- Revision 10: published
- Revision 11: published
- Revision 12: published
0 comments