Testing for existence of a property

JavaScript performance comparison

Test case created by Kevin Ennis

Info

Does bypassing the prototype chain make a difference?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    if (typeof Object.create !== 'function') {
        Object.create = function (o) {
            function F() {}
            F.prototype = o;
            return new F();
        };
    }
   
    var obj1 = {},
        obj2 = Object.create(obj1),
        obj3 = Object.create(obj2),
        obj4 = Object.create(obj3),
        obj5 = Object.create(obj4),
        prop;
};
</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
Dot syntax
prop = obj5.notARealProperty;
pending…
Square bracket syntax
prop = obj5['notARealProperty'];
pending…
hasOwnProperty
prop = obj5.hasOwnProperty('notARealProperty');
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