Data vs. Accessor Properties

JavaScript performance comparison

Test case created by Nicholas C. Zakas

Info

The purpose of this benchmark is to determine if there is a performance difference between data properties and access are properties.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var data = { property: undefined };
    var accessor = {
        get property() {
            // noop
        },
        set property(value) {
            // noop
        }
    };
    var method = { property: function(){} };
};
</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
Write to data property
data.property = true;
pending…
Write to accessor property
accessor.property = true;
pending…
Read from data property
var value = data.property;
pending…
Read from accessor property
var value = accessor.property;
pending…
Calling a method
var value = method.property();
 
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