Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
findIndex update vs for loop update edited 1
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
update via findIndex
21.2 Ops/sec
for loop update
167.6 Ops/sec
Script Preparation code:
var arr = new Array(2000000); arr.fill({ id: 0 }); arr = arr.map((el, idx) => el.id = idx); var findItemIndex = (idToFind, list) => { var index = -1 for (var i = 0; i < list.length; i++) { if (list[i].id === idToFind) { index = i; break; } } return index; } var itemsToUpdate = [{ id: 100, updates: { name: "111" } }, { id: 200, updates: { name: "111" } }, { id: 400, updates: { name: "111" } }, { id: 600, updates: { name: "111" } }, { id: 800, updates: { name: "111" } }]
Tests:
update via findIndex
itemsToUpdate.forEach((t) => { const storedIndex = arr.findIndex((tD) => { return tD.id === t.id }) if(storedIndex >= 0){ arr[storedIndex] = { ...arr[storedIndex], ...t.updates } } })
for loop update
itemsToUpdate.forEach((t) => { const storedIndex = findItemIndex(t.id, arr) if(storedIndex >= 0){ arr[storedIndex] = { ...arr[storedIndex], ...t.updates } } })