Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array push vs reduce
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 18
Operating system:
iOS 18.5
Device Platform:
Mobile
Date tested:
11 months ago
Test name
Executions per second
array push
9943199.0 Ops/sec
optimized push
29546792.0 Ops/sec
reduce
7472282.0 Ops/sec
optimized reduce
28642572.0 Ops/sec
Script Preparation code:
var oldData = { item1: 'olditem1', item2: 'olditem2', item3: 'unchanged' }; var newData = { item1: 'newitem1', item3: 'unchanged', item4: 'something else' };
Tests:
array push
const result = []; Object.entries(oldData).forEach(([key, oldValue]) => { const newValue = newData[key]; if (typeof newValue === 'undefined' || oldValue !== newValue) { result.push(key); } });
optimized push
const result = []; Object.keys(oldData).forEach((key) => { if (oldData[key] !== newData[key]) { result.push(key); } });
reduce
const result = Object.entries(oldData).reduce((accum, [key, oldValue]) => { const newValue = newData[key]; if (typeof newValue === 'undefined' || oldValue !== newValue) { return [...accum, key]; } return accum; }, []);
optimized reduce
const result = Object.keys(oldData).reduce((accum, key) => { if (oldData[key] !== newData[key]) { accum.push(key); } return accum; }, []);