Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
getters vs proxy
(version: 1)
Comparing performance of:
lazy1 vs lazy2 vs lazy3
Created:
9 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function lazy1(prototype, propertyKey, descriptor) { const originalFunction = descriptor.get; descriptor.get = function() { const val = originalFunction.apply(this, arguments); Object.defineProperty(this, propertyKey, { value: val }); return val; } } function lazy2(prototype, propertyKey, descriptor) { const originalFunction = descriptor.get; const cachedKey = `__lazy__${propertyKey}`; descriptor.get = function() { if (!this.hasOwnProperty(cachedKey)) { this[cachedKey] = originalFunction.apply(this, arguments); } return this[cachedKey]; }; } class A { get x() { return 1; } get y() { return 1; } } lazy1(A.prototype, 'x', Object.getOwnPropertyDescriptor(A.prototype, 'x')); lazy2(A.prototype, 'y', Object.getOwnPropertyDescriptor(A.prototype, 'y')); const b = new Proxy({z:1},{get(target, key){return target[key]}}); const a = new A();
Tests:
lazy1
let tot = 0; while(tot < 100) tot+=a.x;
lazy2
let tot = 0; while(tot < 100) tot+=a.y;
lazy3
let tot = 0; while(tot < 100) tot+=b.z;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lazy1
lazy2
lazy3
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!
Comments
Confirm delete:
Do you really want to delete benchmark?