Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
class vs fn
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser:
Chrome 137
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
10 months ago
Test name
Executions per second
create arrClass
49105.2 Ops/sec
create arrFn
46757.3 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
// Класс с ленивой инициализацией class StateClass { constructor() { this._state = null; } getState() { if (this._state === null) { // Имитация более дорогой операции const arr = Array.from({length: 1000}, (_, i) => i * Math.random()); this._state = { data: arr, computed: arr.reduce((a, b) => a + b, 0), timestamp: Date.now() }; } return this._state; } } // Замыкание с ленивой инициализацией function createStateClosure() { let state = null; return function getState() { if (state === null) { // Имитация более дорогой операции const arr = Array.from({length: 1000}, (_, i) => i * Math.random()); state = { data: arr, computed: arr.reduce((a, b) => a + b, 0), timestamp: Date.now() }; } return state; }; } let arrClass; let arrFn;
Tests:
create arrClass
arrClass = Array.from({length: 1000}, (_, i) => new StateClass());
create arrFn
arrFn = Array.from({length: 1000}, (_, i) => createStateClosure());