Backbone.js Collection iteration (v7)

Revision 7 of this benchmark created on


Preparation HTML

<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>

Setup

var M = Backbone.Model.extend({ });
    
    var Col = Backbone.Collection.extend({
      model: M
    });
    
    var a = new Array(5000);
    
    var c = new Col(a);

Test runner

Ready to run.

Testing in
TestOps/sec
Backbone each
c.each(function(m){
    !!m;
});
ready
for loop with collection.at
for (var i = 0, l = c.length; i < l; i++) {
    !!c.at(i);
}
ready
for loop with collection.models
for (var i = 0, l = c.length; i < l; i++) {
    !!c.models[i];
}
ready
Backbone each tweaked
var foo = function(m){
    !!m;
}
c.each(foo);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.