for(;;;) vs forEach vs $.each
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var i,
cachedFunc = function(i){ i / 2; };
window.arr = [];
for (i = 0; i < 10000; i += 1) {
arr.push(i);
}
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
for(;;;) |
|
pending… |
native forEach |
|
pending… |
$.each |
|
pending… |
native forEach (cached func) |
|
pending… |
$.each (cached func) |
|
pending… |
for(;;;) (self func) |
|
pending… |
reverse for(;;;) |
|
pending… |
for(;;;) (no var caching) |
|
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 3: published by Todd
- Revision 4: published by Damon Oehlman
- Revision 5: published
- Revision 6: published by Allen Wirfs-Brock
- Revision 8: published by Allen Wirfs-Brock
- Revision 9: published by mike
- Revision 10: published by mike
- Revision 11: published by mike
- Revision 12: published by mike
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published by Arthur Corenzan
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published
- Revision 22: published by pivolan
- Revision 23: published
- Revision 24: published by Todd
- Revision 25: published by Todd
- Revision 26: published
- Revision 27: published
- Revision 28: published
- Revision 29: published by Ray Baker
- Revision 30: published by Bert Freudenberg
- Revision 31: published
0 comments