Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
nested spread vs forEach push
(version: 1)
Comparing performance of:
spread vs forEach push
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const arrNested = Array.from(Array(1000).keys()); const arr = new Array(1000).fill(null).map((item) => ({ nested: [...arrNested], }));
Tests:
spread
const resultSpread = []; arr.forEach((item) => { resultSpread.push(...item.nested); });
forEach push
const resultNestedLoop = []; arr.forEach((item) => { item.nested.forEach((nestedItem) => resultNestedLoop.push(nestedItem)); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
spread
forEach push
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
spread
372.1 Ops/sec
forEach push
266.9 Ops/sec
Related benchmarks:
comparing push vs spread one by one
spread vs push 2
spread vs push - simple2
forEach concat vs reduce push performance
forEach concat vs reduce push vs forEach push vs reduce concat performance
Array: Array.from vs Spread
Array loop vs foreach vs map forsk
Array loop vs foreach vs map forsk2
spread vs forEach push v4
Comments
Confirm delete:
Do you really want to delete benchmark?