Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Optimizing Code: Object vs Array II
(version: 2)
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: 10000 }, (_, i) => ({ id: `id${i + 1}` })); var target = 'id5000'; 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:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 OPR/122.0.0.0
Browser/OS:
Opera 122 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array Find
35524.7 Ops/sec
Object Find
77332416.0 Ops/sec
Related benchmarks:
obj vs array again
set + array.from + map vs map + set
Array loop vs foreach vs map saved
Array find by id or indexOf
Array.find vs Map
Array loop vs foreach vs map forsk
Array loop vs foreach vs map forsk2
Map vs Find to change one el in array of objects
Optimizing Code: Object vs Array
Comments
Confirm delete:
Do you really want to delete benchmark?