class-perfs (v11)

Revision 11 of this benchmark created by army8735 on


Preparation HTML

<script src='http://documentcloud.github.com/underscore/underscore.js'></script>
<script src='http://documentcloud.github.com/backbone/backbone-min.js'></script>
<script src='http://seajs.org/dist/sea.js'></script>
<script src='http://assets.spmjs.org/arale/class/1.0.0/class.js'></script>
<script src='http://assets.spmjs.org/arale/class/1.1.0/class.js'></script>
<script src='http://assets.spmjs.org/arale/class/1.2.0/class.js'></script>
<script src='http://assets.spmjs.org/arale/class/2.0.0/class.js'></script>
<script>
var Class10 = seajs.require('arale/class/1.0.0/class');
var Class11 = seajs.require('arale/class/1.1.0/class');
var Class12 = seajs.require('arale/class/1.2.0/class');
var Class20 = seajs.require('arale/class/2.0.0/class');
var AClass = (function() {
        function inheritPrototype(subType, superType) {
                var prototype = Object.create(superType.prototype);
                prototype.constructor = subType;
                subType.prototype = prototype;
                //继承static变量
                Object.keys(superType).forEach(function(k) {
                        subType[k] = superType[k];
                });
                return subType;
        }
        function wrap(fn) {
                fn.extend = function(sub) {
                        inheritPrototype(sub, fn);
                        return wrap(sub);
                }
                fn.methods = function(o) {
                        Object.keys(o).forEach(function(k) {
                                fn.prototype[k] = o[k];
                        });
                        return fn;
                };
                fn.statics = function(o) {
                        Object.keys(o).forEach(function(k) {
                                fn[k] = o[k];
                        });
                        return fn;
                };
                return fn;
        }
        function klass(cons) {
                return wrap(cons || function() {});
        }
        klass.extend = inheritPrototype;
        return klass;
})();
</script>
<script src="http://libs.baidu.com/mootools/1.4.5/mootools-yui-compressed.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
backbone
var Animal = Backbone.Model.extend({
  initialize: function(name) {
    this.name = name;
  },
  talk: function() {
    return 'I am ' + this.name;
  }
});

var Bird = Animal.extend({
  initialize: function(name) {
    Animal.prototype.initialize.call(this, name);
  },
  fly: function() {
    return 'I am flying';
  }
});

new Animal();
var bird = new Bird();
bird.talk();
bird.fly();
ready
mootools
var Animal = new Class({
  initialize: function(name) {
    this.name = name;
  },
  talk: function() {
    return 'I am ' + this.name;
  }
});

var Bird = new Class({
  Extends: Animal,
  initialize: function(name) {
    this.parent(name);
  },
  fly: function() {
    return 'I am flying';
  }
});

new Animal();
var bird = new Bird();
bird.talk();
bird.fly();
ready
arale/class@1.0.0
var Animal = Class10.create({
  initialize: function(name) {
    this.name = name;
  },
  talk: function() {
    return 'I am ' + this.name;
  }
});

var Bird = Animal.extend({
  initialize: function(name) {
    Bird.superclass.initialize.call(this, name);
  },
  fly: function() {
    return 'I am flying';
  }
});

new Animal();
var bird = new Bird();
bird.talk();
bird.fly();
ready
coffeescript
// Generated by CoffeeScript 1.6.2

// class Animal
//   constructor: (@name) ->
//   talk: ->
//     "I am #{@name}"

// class Bird extends Animal
//   fly: ->
//     "I am flying"

// new Animal
// bird = new Bird
// bird.talk()
// bird.fly()

(function() {
  var Animal, Bird, bird, _ref,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  Animal = (function() {
    function Animal(name) {
      this.name = name;
    }

    Animal.prototype.talk = function() {
      return "I am " + this.name;
    };

    return Animal;

  })();

  Bird = (function(_super) {
    __extends(Bird, _super);

    function Bird() {
      _ref = Bird.__super__.constructor.apply(this, arguments);
      return _ref;
    }

    Bird.prototype.fly = function() {
      return "I am flying";
    };

    return Bird;

  })(Animal);

  new Animal;

  bird = new Bird;

  bird.talk();

  bird.fly();

}).call(this);
ready
arale/class@1.1.0
var Animal = Class11.create({
  initialize: function(name) {
    this.name = name;
  },
  talk: function() {
    return 'I am ' + this.name;
  }
});

var Bird = Animal.extend({
  initialize: function(name) {
    Bird.superclass.initialize.call(this, name);
  },
  fly: function() {
    return 'I am flying';
  }
});

new Animal();
var bird = new Bird();
bird.talk();
bird.fly();
ready
arale/class@1.2.0
var Animal = Class12.create({
  initialize: function(name) {
    this.name = name;
  },
  talk: function() {
    return 'I am ' + this.name;
  }
});

var Bird = Animal.extend({
  initialize: function(name) {
    Bird.superclass.initialize.call(this, name);
  },
  fly: function() {
    return 'I am flying';
  }
});

new Animal();
var bird = new Bird();
bird.talk();
bird.fly();
ready
arale/class@2.0.0
var Animal = Class20.create({
  initialize: function(name) {
    this.name = name;
  },
  talk: function() {
    return 'I am ' + this.name;
  }
});

var Bird = Animal.extend({
  initialize: function(name) {
    Bird.superclass.initialize.call(this, name);
  },
  fly: function() {
    return 'I am flying';
  }
});

new Animal();
var bird = new Bird();
bird.talk();
bird.fly();
ready
AClass
var Animal = AClass(function(name) {
  this.name = name;
}).methods({
  talk: function() {
    return 'I am ' + this.name;
  }
});
var Bird = Animal.extend(function(name) {
  Animal.call(this, name);
}).methods({
  fly: function() {
    return 'I am flying';
  }
});

new Animal();
var bird = new Bird();
bird.talk();
bird.fly();
ready

Revisions

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