Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Chrome 118
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Read directly from prop 37484568.0 Ops/sec
Set directly to prop 37223524.0 Ops/sec
Read from getter 37022728.0 Ops/sec
Set to setter 36859136.0 Ops/sec
Script Preparation code:
x
 
class MyObj {
    prop = undefined
    get propAccessor() {
        return this.prop;
    }
    set propAccessor(val) {
        this.prop = val;
    }
}
var obj = new MyObj();
Tests:
  • Read directly from prop

     
    var value = obj.prop;
  • Set directly to prop

     
    obj.prop = 123;
  • Read from getter

     
    var value = obj.propAccessor;
  • Set to setter

     
    obj.propAccessor = 123;