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; Ubuntu; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser:
Firefox 141
Operating system:
Ubuntu
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
lazy1
7833023.0 Ops/sec
lazy2
8075145.5 Ops/sec
proxy
392403.3 Ops/sec
property
7380658.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;