Prototype lookup
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
0 levels |
|
pending… |
1 level |
|
pending… |
2 levels |
|
pending… |
3 levels |
|
pending… |
4 levels |
|
pending… |
5 levels |
|
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:
- Revision 1: published by Stéphan Kochen
- Revision 2: published
- Revision 3: published
0 comments