Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Optimizing Code: Object vs Array
(version: 4)
Comparing performance of:
Array Find vs Object Find
Created:
5 months ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var arr = Array.from({ length: 10 }, (_, i) => ({ id: `id${i + 1}` })); var target = 'id5'; const buildMap = (() => { const cache = new WeakMap(); return function (array) { if (cache.has(array)) { return cache.get(array); } const out = {}; for (let i = 0; i < array.length; i++) { const item = array[i]; out[item.id] = item; } cache.set(array, out); return out; }; })();
Tests:
Array Find
arr.find(x => x.id === target);
Object Find
const map = buildMap(arr); map[target];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array Find
Object Find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array Find
16973906.0 Ops/sec
Object Find
40182024.0 Ops/sec
Related benchmarks:
Array loop vs s map
.map vs .forEach
Array loop vs foreach vs map x1
For loop differences
Comparing for, foreach and map
Array loop vs foreach vs map saved
Array loop vs foreach vs map forsk
Array loop vs foreach vs map forsk2
Optimizing Code: Object vs Array II
Comments
Confirm delete:
Do you really want to delete benchmark?