Backbone.js Collection iteration

JavaScript performance comparison

Revision 5 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(5000);
   
    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
for loop in
for (idx in c.models) {
    var m = c.models[idx];
    !!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…
collection.each
c.each(function(m){
    !!m;
});
pending…
for loop with assignment
for (var i = 0, m; m = c.models[i]; ++i) {
    !!m;
}
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