Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array item replacement performance comparisons
(version: 0)
Comparing performance of:
Slice and splice vs Slice and concat vs Slice and spread vs Spread and splice
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = Array.from({ length: 5000 }, (item, index) => index);
Tests:
Slice and splice
const changeIndex = 111; const newTestArray = arr.slice(); newTestArray.splice(changeIndex, 1, 8080);
Slice and concat
const changeIndex = 222; const newTestArray = arr.slice(0, changeIndex).concat(13, arr.slice(changeIndex + 1));
Slice and spread
const changeIndex = 333; const newTestArray = [ ...arr.slice(0, changeIndex), 42, ...arr.slice(changeIndex + 1)];
Spread and splice
const changeIndex = 444; const newTestArray = [...arr]; newTestArray.splice(changeIndex, 1, 1111);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Slice and splice
Slice and concat
Slice and spread
Spread and splice
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
`Array.slice(-1)[0]` vs `Array[Array.length]` for 10000 length
Add item at index
Slice vs Splice vs Shift (Large Array)
`array.slice(-1)[0]` vs `array[array.length - 1]`
Slice vs Splice vs Shiftxxxxxx
Comments
Confirm delete:
Do you really want to delete benchmark?