third party each loops

JavaScript performance comparison

Revision 2 of this test case created

Info

Tests the performance of various each loops

Preparation code

<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>


<script type="text/javascript">
//gaffa.js fastEach

    Array.prototype.fastEach = function (callback) {
        for (var i = 0; i < this.length; i++) {
            if(callback(this[i], i, this)) break;
        }
    };

//gaffa.js fastEach with no convenience params

    Array.prototype.superfastEach = function (callback) {
        var length = this.length;
        for (var i = 0; i < length; i++) {
            callback(this[i]);
        }
    };

//some big array
var data = [];

//useless data
for(var i = 0; i < 10000; i++){
    data[i] = 1;
}
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
native each
data.forEach(function(value){
    value *= 1;
});
pending…
gaffa fastEach
data.fastEach(function(value){
    value *= 1;
});
pending…
underscore each
_.each(data, function(value){
    value *= 1;
});
pending…
normal for
for( var i = 0; i < data.length; i++){
    data[i] *= 1;
}
pending…
superfastEach
data.superfastEach(function(value){
    value *= 1;
});
pending…
jquery each
$.each(data, function(value){
    value *= 1;
});
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:

0 comments

Add a comment