Backbone.js Collection iteration

JavaScript performance comparison

Revision 4 of this test case created by

Preparation code

<script src=""></script>
<script src=""></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);


Preparation code output

<script src=""></script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Backbone each
for (idx in c.models) {
    var m = c.models[idx];
for loop with
for (var i = 0, l = c.length; i < l; i++) {
for loop with collection.models
for (var i = 0, l = c.length; i < l; i++) {

Compare results of other browsers


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