Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
get x versus array[0]
(version: 1)
Comparing performance of:
array[0] vs set / get
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
// Setup phase - common for both tests const size = 10000; const array = new Array(16).fill(1); // Fill array with ones for consistency const obj = { get x() { return array[0]; }, set x(value) { array[0] = value; } };
Tests:
array[0]
let sum = 0; for (let i = 0; i < size; i++) { array[0] = Math.random () * 1000; sum += array[0]; }
set / get
let sum = 0; for (let i = 0; i < size; i++) { obj.x = Math.random () * 1000; sum += obj.x; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array[0]
set / get
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_3_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/136.2 Mobile/15E148 Safari/605.1.15
Browser/OS:
Mobile Safari 18 on iOS 18.3.2
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array[0]
76786.6 Ops/sec
set / get
75136.3 Ops/sec
Related benchmarks:
js array perfomance
at vs index
This site broken
Range vs for of
TestArrayAllocationv2
array vs int32array vs map fixed
Another array[len - 1] vs array.at(-1)
DDS Array vs Set - performance v4
Array.from vs Array.fill (zeroes)
Comments
Confirm delete:
Do you really want to delete benchmark?