HTML Preparation code:
AخA
 
1
<b>Comparing performance of:</b> Read from data property vs Write to data property vs Read from accessor method vs Write to mutator method vs Read from object literal property vs Write to object literal property vs Read from object literal property on prototype vs Write to object literal property on prototype
Script Preparation code:
x
 
var data = {
  property: property
};
var property = undefined;
var method = {
  getProperty: function() {
    return property;
  },
  setProperty: function(value) {
    property = value;
  }
};
var objectLiteralAccessor = {
  get property() {
    return property;
  },
  set property(value) {
    property = value;
  }
};
function Class() {
}
Class.prototype = {
  get property() {
    return property;
  },
  set property(value) {
    property = value;
  },
  getProperty() {
    return property;
  },
  setProperty(value) {
    property = value;
  }
};
    
var prototypeAccessor = new Class();
Tests:
  • Read from data property

     
    var value = data.property;
  • Write to data property

     
    data.property = true;
  • Read from accessor method

     
    var value = method.getProperty();
  • Write to mutator method

     
    method.setProperty(true);
  • Read from object literal property

     
    var value = objectLiteralAccessor.property;
  • Write to object literal property

     
    objectLiteralAccessor.property = true;
  • Read from object literal property on prototype

     
    var value = prototypeAccessor.property;
  • Write to object literal property on prototype

     
    prototypeAccessor.property = true;
  • Read with prototype method

     
    var value = prototypeAccessor.getProperty();
  • Write with prototype method

     
    prototypeAccessor.setProperty(true);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Read from data property
    Write to data property
    Read from accessor method
    Write to mutator method
    Read from object literal property
    Write to object literal property
    Read from object literal property on prototype
    Write to object literal property on prototype
    Read with prototype method
    Write with prototype method

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 months ago)
Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0
Firefox 133 on Linux
View result in a separate tab
Test name Executions per second
Read from data property 2388566528.0 Ops/sec
Write to data property 1466171776.0 Ops/sec
Read from accessor method 649753152.0 Ops/sec
Write to mutator method 1341940864.0 Ops/sec
Read from object literal property 649740544.0 Ops/sec
Write to object literal property 1275260160.0 Ops/sec
Read from object literal property on prototype 677672448.0 Ops/sec
Write to object literal property on prototype 1364491520.0 Ops/sec
Read with prototype method 848672320.0 Ops/sec
Write with prototype method 1359838464.0 Ops/sec