Backbone Vs John Resig's Simple JavaScript Inheritance

JavaScript performance comparison

Revision 4 of this test case created


This is a performance test of object creation between Backbone models, and John Resig's Simple JavaScript Inheritance script.

Preparation code

<script src="">
<script src="">
<script src="">
  /* Simple JavaScript Inheritance
 * By John Resig
 * MIT Licensed.

  // Inspired by base2 and Prototype
  (function() {
    var a = false,
        b = /xyz/.test(function() {
      }) ? /\b_super\b/ : /.*/;
    this.Class = function() {};
    Class.extend = function(g) {
      var f = this.prototype;
      a = true;
      var e = new this();
      a = false;
      for (var d in g) {
        e[d] = typeof g[d] == "function" && typeof f[d] == "function" && b.test(g[d]) ? (function(h, i) {
          return function() {
            var k = this._super;
            this._super = f[h];
            var j = i.apply(this, arguments);
            this._super = k;
            return j
        })(d, g[d]) : g[d]

      function c() {
        if (!a && this.init) {
          this.init.apply(this, arguments)
      c.prototype = e;
      c.prototype.constructor = c;
      c.extend = arguments.callee;
      return c
Benchmark.prototype.setup = function() {
    window.array = [];
    myModel = Backbone.Model.extend({
      afun: function() {}
    ResigsClass = Class.extend({
      afun: function() {}

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
Create Backbone.Model objects
  afun: function() {}
Create new instance of Backbone.Model
array.push(new myModel());
John Resig Approach
array.push(new ResigsClass());

Compare results of other browsers


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:


Richard commented :

Seems like Apples/Oranges to me. What's the objective here, are you suggesting that people shouldn't use Backbone because it has 'slow' class inheritance?

Alan Peters commented :

Cool test. I don't usually select Resig for the performance but for its elegance. It's sort of a matter of style/religion.

Have you looked at Resig Inheritance vs Zepto/JQuery?

Comment form temporarily disabled.

Add a comment