direct vs prop

JavaScript performance comparison

Test case created by InviS

Info

Test direct object property assignment vs getter/setter .prop

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var o = {
      prop = {},
      _prop: function (name, value) {
        if (typeof value === 'undefined') {
          return this.prop[name];
        } else {
          this.prop[name] = value;
        }
      }
    };
};
</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
Direct
o.prop.somekey = 'somevalue';
var a = o.prop.somekey;
pending…
Property access
o._prop('somekey', 'somevalue');
var a = o._prop('somekey');
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