Direct property access vs getter function

JavaScript performance comparison

Revision 2 of this test case created by vincent piel

Preparation code

<script>
  var foo = {
   bar: 5,
   getBar: function() {
    return this.bar;
   }
  };

  var foo2 = {
   get bar() { return foo2._bar; },
  _bar : 5    
   };
</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
foo.bar;
pending…
Getter function
foo.getBar();
pending…
Getter;
foo2.bar;
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