Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
update Element in a array test _tarcisio.magno
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser:
Chrome 143
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
5 months ago
Test name
Executions per second
Map Method
16.7 Ops/sec
Slice Method
3.8 Ops/sec
Script Preparation code:
var oldData = Array.from({ length: 10000000 }, (_, index) => ({ id: index + 1, name: `name_${index+1}`, version: "0", active: true })); var row = { id: 1 } function sliceMethod(oldData, row) { const index = oldData.findIndex( item => item.id === row.id ); return { queues: { data: [ ...oldData.slice(0, index), { ...oldData[index], active: true, version: String( +oldData[index].version + 1 ) }, ...oldData.slice(index + 1) ] } }; } function mapMethod(oldData, row) { const data = oldData.map(item => { if (item.id !== row.id) return item return { ...item, active: true, version: String(+item.version + 1) }; }) return { queues: { data } }; }
Tests:
Map Method
mapMethod(oldData, row);
Slice Method
sliceMethod(oldData,row);