forEach vs for vs for..in vs while
JavaScript performance comparison
Preparation code
<script>
var j, array = []
for(j=0; j<= 5000; j++){
array[j]= j;
}
var _foreach=function(array,callback){
var len = array.length;
for(var i=0; i< len; i++) callback(array[i],i);
};
var add = function(a, b) {return a + b};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
for
|
|
pending… |
forEach
|
|
pending… |
for in
|
|
pending… |
for (2)
|
|
pending… |
while
|
|
pending… |
for (3)
|
|
pending… |
for with foreach function
|
|
pending… |
reduce
|
|
pending… |
while2
|
|
pending… |
for in 2
|
|
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.
- Revision 1: published Mohamed Ted
- Revision 2: published
- Revision 3: published Christophe
- Revision 4: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published Wil Moore III
0 Comments