Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array Access vs Object Access with Random Value
(version: 1)
Comparing performance of:
Array vs Array with Deconstruct vs Object vs Object with Deconstruct
Created:
6 months ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const data = Array.from({ length: 4 * 10000 }, () => Math.random()); const arr = Array(10000).fill(0); const obj = Array(10000).fill(0); for (let i = 0; i < 10000; i++) { const b = i * 4; arr[i] = [data[b], data[b + 1], data[b + 2], data[b + 3]]; obj[i] = { x: data[b], y: data[b + 1], w: data[b + 2], h: data[b + 3] }; }
Tests:
Array
let result = 0; for (let i = 0; i < 10000; i++) { result += arr[i][0] + arr[i][1] + arr[i][2] + arr[i][3]; }
Array with Deconstruct
let result = 0; for (let i = 0; i < 10000; i++) { const [x, y, w, h] = arr[i]; result += x + y + w + h; }
Object
let result = 0; for (let i = 0; i < 10000; i++) { result += obj[i].x + obj[i].y + obj[i].w + obj[i].h; }
Object with Deconstruct
let result = 0; for (let i = 0; i < 10000; i++) { const { x, y, w, h } = obj[i]; result += x + y + w + h; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array
Array with Deconstruct
Object
Object with Deconstruct
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0
Browser/OS:
Chrome 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array
19512.0 Ops/sec
Array with Deconstruct
15459.5 Ops/sec
Object
21434.3 Ops/sec
Object with Deconstruct
41120.4 Ops/sec
Related benchmarks:
Random I/O various arrays
Sparse array vs Map for random access and iteration
Large but empty Array versus Small Object (Creation wise)
Fill an MxN 2D nested array with random numbers
JS Object Creation vs Pooling
Get from object vs get from map
array vs obj
Array.at(i) vs Array[i]
100 array
Comments
Confirm delete:
Do you really want to delete benchmark?