Prototype lookup

JavaScript performance comparison

Revision 2 of this test case created

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 = {
  0:0,1:1,2:2,3:3,4:4,5:5,length:6
};
var l1 = inherit(l0);
var l2 = inherit(l1);
var l3 = inherit(l2);
var l4 = inherit(l3);
var l5 = inherit(l4);
function loop(obj){
  for (var i = 0, len=obj.length; i<len;i++)obj[i];
}
</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
loop(l0);
pending…
1 level
loop(l1);
pending…
2 levels
loop(l2);
pending…
3 levels
loop(l3);
pending…
4 levels
loop(l4);
pending…
5 levels
loop(l5);
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