Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
map vs splice test
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/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
map
78247.8 Ops/sec
slice
85965.7 Ops/sec
Tests:
map
const events = []; let max = 1000; while (max > 0) { events.push({ id: max, title: `t ${max}`}); max --; } const event = { id: 500, title: 'foo' }; const index = events.findIndex((el) => el.id === event.id); let updated; if (index === -1) { updated = events.map((el) => el.id === event.id ? event : el); } else { updated = [ ...events, event ]; }
slice
const events = []; let max = 1000; while (max > 0) { events.push({ id: max, title: `t ${max}`}); max --; } const event = { id: 500, title: 'foo' }; const index = events.findIndex((el) => el.id === event.id); let updated; if (index === -1) { updated = [ ...events.slice(0, index), event, ...events.slice(index + 1) ]; } else { updated = [ ...events, event ]; }