Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
4-element Array.slice() vs. Spread operator
(version: 1)
For times when a shallow copy of an Array is needed, what is the performance difference between these 2 methods.
Comparing performance of:
Array.slice() vs Spread operator vs Array.slice() with start and end
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js'></script>
Script Preparation code:
var arr = [1.9, 2.8, 3.7, 4.6];
Tests:
Array.slice()
var myCopy = arr.slice()
Spread operator
var myCopy = [...arr]
Array.slice() with start and end
var myCopy = arr.slice(0, 3)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array.slice()
Spread operator
Array.slice() with start and end
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0
Browser/OS:
Firefox 128 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.slice()
12292018.0 Ops/sec
Spread operator
7243843.0 Ops/sec
Array.slice() with start and end
6956644.0 Ops/sec
Related benchmarks:
Lodash cloneDeep vs Lodash clone vs Array.slice() vs. Object.assign()
Lodash cloneDeep vs. Lodash clone vs. Array.slice() vs. Array.slice(0) vs. Object.assign()
Lodash cloneDeep vs Lodash clone vs Array.splice() vs. Object.assign()
Lodash cloneDeep vs Lodash clone vs Array.splice() vs. Object.assign() vs Array.slice() vs Array.slice(0)
JavaScript array copy via spread op vs slice
Slice vs spread array
Array.slice() vs. Spread operator
Array.slice() vs. Spread operator (10000 items)
4-number (float) Array.slice() vs. Spread operator
Comments
Confirm delete:
Do you really want to delete benchmark?