backbone models

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
 <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.9/backbone-min.js"></script>

<script>
var CoolModel = Backbone.Model.extend({

    defaults: {
        id: null,
        description: null,
        attr: null,
        another_attr: null
    }

});
var CoolCollection = Backbone.Collection.extend({
  model: CoolModel
});

var CoolModel2 = Backbone.Model.extend({

});
var CoolCollection2 = Backbone.Collection.extend({
  model: CoolModel2
});

</script>
 
<script>
Benchmark.prototype.setup = function() {
    var OBJS = [];
    var mLen = 10;
    while(mLen--){
        OBJS.push({
            id: mLen,
            description: Math.random(),
            attr: 'lorem ipsum dolor',
            another_attr: true
        });
    }
   
    var JSONobjs = JSON.stringify(OBJS);
   
   
   
   
};

Benchmark.prototype.teardown = function() {
    OBJS = [];
};
</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
with defaults
var coll = new CoolCollection(JSONobjs, {
    parse: true
});
pending…
without defaults
var coll = new CoolCollection2(JSONobjs, {
    parse: true
});
pending…

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

Compare results of other browsers

0 comments

Add a comment