Object Initalization / Hidden Classes

JavaScript performance comparison

Revision 4 of this test case created by Jean Vincent

Info

Testing the speed of various object initialization methods to evidence the benefit of (v8) hidden classes for objects which final attributes are floats.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    window.test = function (a) {
        return a || undefined;
    }
};
</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
Null
window.asdf = {a:null,b:null,c:null};
test(asdf);
asdf.a = Math.random();
asdf.b = Math.random();
asdf.c = Math.random();
 
pending…
Blank
window.uiop = {};
test(uiop);
uiop.x = Math.random();
uiop.y = Math.random();
uiop.z = Math.random();
 
pending…
Undefined
window.qwerty = {a:undefined,b:undefined,c:undefined};
test(qwerty);
qwerty.d = Math.random();
qwerty.e = Math.random();
qwerty.f = Math.random();
 
pending…
Number
window.ghjkl = {a:0,b:0,c:0};
test(ghjkl);
ghjkl.t = Math.random();
ghjkl.u = Math.random();
ghjkl.v = Math.random();
 
pending…
Boolean
window.zxcv = {a:false,b:false,c:false};
test(zxcv);
zxcv.g = Math.random();
zxcv.h = Math.random();
zxcv.i = Math.random();
 
pending…
String
window.bnm = {a:'',b:'',c:''};
test(bnm);
bnm.q = Math.random();
bnm.r = Math.random();
bnm.s = Math.random();
pending…
Float
window.bnm = {a: 0.0, b: 0.0, c: 0.0};
test(bnm);
bnm.q = Math.random();
bnm.r = Math.random();
bnm.s = Math.random();
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