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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Browser:
Chrome 109
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
array push
690035.4 Ops/sec
optimized push
572206.5 Ops/sec
reduce
819581.9 Ops/sec
optimized reduce
617616.9 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; }, []);