Object extension vs function call

JavaScript performance comparison

Test case created by Alex Gyoshev

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function preventDefault() {
        this._isDefaultPrevented = true;
    }
   
    function isDefaultPrevented() {
        return this._isDefaultPrevented;
    }
   
    eventPrototype = {
      preventDefault: preventDefault,
      isDefaultPrevented: isDefaultPrevented
    }
   
    function triggerProto(e) {
        e = e || {};
        e.__proto__= eventPrototype;
        e.preventDefault();
    }
    function triggerObject(e) {
        e = e || {};
        e.preventDefault = preventDefault;
        e.isDefaultPrevented = isDefaultPrevented;
        e.preventDefault();
    }
};
</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
triggerObject
triggerObject({ field: "foo" });
pending…
triggerProto
triggerProto({ field: "foo" });
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment