Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
lazy getters vs proxy vs property
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser:
Chrome 138
Operating system:
Linux
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
lazy1
10691199.0 Ops/sec
lazy2
10723576.0 Ops/sec
proxy
627352.3 Ops/sec
property
8863970.0 Ops/sec
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 { constructor(){ this.w = 1; } 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({},{get(target, key){return 1;}}); 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;
proxy
let tot = 0; while(tot < 100) tot+=b.z;
property
let tot = 0; while(tot < 100) tot+=a.w;