Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
class vs fn: 3
(version: 1)
Comparing performance of:
arrClass vs arrFn
Created:
10 months ago
by:
Guest
Jump to the latest result
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 { 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; } }; } const arrClass = Array.from({length: 1000}, (_, i) => new StateClass()); const arrFn = Array.from({length: 1000}, (_, i) => createStateClosure()); arrClass.forEach(i => i.getState()); arrFn.forEach(i => i.getState());
Tests:
arrClass
arrClass.forEach(i => i.getState());
arrFn
arrFn.forEach(i => i.getState());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
arrClass
arrFn
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser/OS:
Firefox 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
arrClass
271501.8 Ops/sec
arrFn
290557.8 Ops/sec
Related benchmarks:
fast_deep_equal - lodash.isEqual test567l898978666
а я думал создание итератора будет дороже
双轴图刻度对齐算法性能对比
双轴图对齐算法性能对比
双轴图对齐算法性能对比(version2)
3Intl.collator O(N*M) vs native String.prototype.includes O(N+M)ы2334
3Intl.collator O(N*M) vs native String.prototype.includes O(N+M)ы234
class vs fn
class vs fn: 2
Comments
Confirm delete:
Do you really want to delete benchmark?