Backbone.js Collection iteration

JavaScript performance comparison

Revision 8 of this test case created

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.0/backbone-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var M = Backbone.Model.extend({ });
   
    var Col = Backbone.Collection.extend({
      model: M
    });
   
    var a = new Array(500000);
   
    var c = new Col(a);
};
</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
Backbone each
c.each(function(m){
    !!m;
});
pending…
for loop with collection.at
for (var i = 0, l = c.length; i < l; i++) {
    !!c.at(i);
}
pending…
for loop with collection.models
for (var i = 0, l = c.length; i < l; i++) {
    !!c.models[i];
}
pending…
Backbone each tweaked
var foo = function(m){
    !!m;
}
c.each(foo);
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