Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array push vs reduce
(version: 0)
Comparing performance of:
array push vs optimized push vs reduce vs optimized reduce
Created:
3 years ago
by:
Guest
Jump to the latest result
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; }, []);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
array push
optimized push
reduce
optimized reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 YaBrowser/25.8.0.0 Safari/537.36
Browser/OS:
Yandex Browser 25 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array push
6227792.0 Ops/sec
optimized push
15622759.0 Ops/sec
reduce
11509996.0 Ops/sec
optimized reduce
15955691.0 Ops/sec
Related benchmarks:
Spread operator vs Array.push vs array[lastIndex]
Pushing items via Array.push vs. Spread Operator
Reducer push vs reducer spread
push vs spread (reduce array)
Comments
Confirm delete:
Do you really want to delete benchmark?