Prototype lookup

JavaScript performance comparison

Test case created by Stéphan Kochen

Info

Benchmarks performance of a lookup through several levels of prototype inheritance.

Preparation code

<script>
function ctor() {}
function inherit(obj) {
  ctor.prototype = obj;
  return new ctor();
}

var l0 = {
  foobar: function(x, y) {
    return x + Math.pow(2, y);
  }
};
var l1 = inherit(l0);
var l2 = inherit(l1);
var l3 = inherit(l2);
var l4 = inherit(l3);
var l5 = inherit(l4);
</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
0 levels
var x = l0.foobar();
pending…
1 level
var x = l1.foobar();
pending…
2 levels
var x = l2.foobar();
pending…
3 levels
var x = l3.foobar();
pending…
4 levels
var x = l4.foobar();
pending…
5 levels
var x = l5.foobar();
pending…

Compare results of other browsers

Revisions

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:

0 comments

Add a comment