getter vs function prop vs prop

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Test() {
      this._prop = 1;
    }
   
   
    Test.prototype.getProp1 = function() {
      return this._prop;
    }
   
    Object.defineProperty(Test.prototype, "getProp2", {
      get: function() {
        return this._prop;
      }
    })
   
    var test = new Test(),
      a;
};
</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
function
a = test.getProp1();
pending…
getter
a = test.getProp2;
pending…
field
a = test._prop;
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