object-extension

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var base = {
      initialize: function () {
      },
      someFunction: function () {
      },
      someOtherFunction: function () {
      },
      aProperty: 20,
      anotherImportantProperty: 30
    };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Loop
var extension = {
  aProperty: 10,
  someOtherFunction: function () {
  },
  aNewFunction: function () {
  },
  aNewProperty: 4
};
for (var key in extension)
  base[key] = extension[key];

 
pending…
Function
(function () {
  this.aProperty = 10;
  this.someOtherFunction = function () {};
  this.aNewFunction = function () {};
  this.aNewProperty = 4;
}).call(base);
 
pending…
Direct Assignment
base.aProperty = 10;
base.someOtherfunction = function () {};
base.aNewFunction = function () {};
base.aNewProperty = 4;
 
pending…
Local Variable Caching
var b = base
b.aProperty = 10;
b.someOtherFunction = function () {};
b.aNewFunction = function () {};
b.aNewProperty = 4;
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