Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Cloning Array
(version: 1)
Comparing performance of:
Spread vs ForEach with push vs For with pre-allocated array
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const userArray = new Array(100000).fill({firstName: 'lorenzo', lastName: 'gomez'});
Tests:
Spread
const spreadCopy = [...userArray]
ForEach with push
const forEachCopy = []; userArray.forEach(user => { forEachCopy.push(user); });
For with pre-allocated array
const preAllocatedArray = new Array(100000); for(let i= 0; i < 100000; i++){ preAllocatedArray[i] = userArray[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Spread
ForEach with push
For with pre-allocated array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
Browser/OS:
Chrome 132 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Spread
3857.7 Ops/sec
ForEach with push
414.4 Ops/sec
For with pre-allocated array
2115.7 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?