Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test JS getter/setter
(version: 0)
Comparing performance of:
obj.aSetter(2); vs obj.aGetter(); vs obj.a = 2; vs obj.a;
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = {}; var _a = 1; obj._a = 1; obj.aGetter = function() { return _a; } obj.aSetter = function(val) { _a = val; } Object.defineProperty(obj, 'a', { enumerable: true, get: function () { return _a; }, set: function(val) { _a = val; } });
Tests:
obj.aSetter(2);
obj.aSetter(2);
obj.aGetter();
obj.aGetter();
obj.a = 2;
obj.a = 2;
obj.a;
obj.a;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
obj.aSetter(2);
obj.aGetter();
obj.a = 2;
obj.a;
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
undefined vs. typeof vs. in vs. Object.prototype.hasOwnProperty
ES5 setter vs func
const a = Object.getPrototypeOf({})
hasOwnProperty vs hasOwnProperty .call
Comments
Confirm delete:
Do you really want to delete benchmark?