function vs jquery extend vs object prototype (v9)

Revision 9 of this benchmark created on


Description

In FF3.6/Win, the execution part (the function calls) have nearly identical running times, so I included the function declarations themselves in the test cases.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
function foo()
function aFoo() {
  var x,i;
  for (i = 0; i < 10; i++) {
    x = Math.random();
  }
}
aFoo();
ready
var bar = function()
var aBar = function() {
    var x,i;
    for (i = 0; i < 10; i++) {
      x = Math.random();
    }
    };
aBar();
ready
$.extend
$.extend({
  aBaz: function() {
    var x,i;
    for (i = 0; i < 10; i++) {
      x = Math.random();
    }
  }
});
$.aBaz();
ready
Object.prototype
Object.prototype.aQuux = function() {
  var x,i;
  for (i = 0; i < 10; i++) {
    x = Math.random();
  }
};
var obj = {};
obj.aQuux();
ready
plain code
var x,i;
for (i = 0; i < 10; i++) {
  x = Math.random();
}
ready
function aFoo() {

}

$.extend(aFoo.prototype, {
  r: function() {
    var x,i;
    for (i = 0; i < 10; i++) {
      x = Math.random();
    }
  }
});
var x = new aFoo();
x.r();
ready

Revisions

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