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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
array push
7118202.5 Ops/sec
optimized push
15791078.0 Ops/sec
reduce
12611294.0 Ops/sec
optimized reduce
16744813.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; }, []);