jQuery Class.create vs Prototype Class.create vs pure JS function

Benchmark created by Avinash on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://digg.googlecode.com/files/Class-0.0.2.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>

Setup

var result = '';

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery Class.create
var Animal = Class.create({
  init: function(name, sound) {
    this.name = name;
    this.sound = sound;
  },
  speak: function() {
    result = (this.name + " says: " + this.sound + "!");
  }
});

var cat = new Animal('Kitty', 'Meow');
cat.speak();
ready
Prototype Class.create
var Animal = Class.create({
  initialize: function(name, sound) {
    this.name  = name;
    this.sound = sound;
  },

  speak: function() {
    alert(this.name + " says: " + this.sound + "!");
  }
});
var cat = new Animal('Kitty', 'Meow');
cat.speak();
ready
Pure JS
function Animal(name, sound) {
  this.name = name;
  this.sound = sound;
}

Animal.prototype.speak = function() {
  result = (this.name + " says: " + this.sound + "!");
}

var cat = new Animal('Kitty', 'Meow');
cat.speak();
ready

Revisions

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