Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS unshift vs splice vs unshift + splice (3 possibilities) FINAL RESULT!
(version: 4)
Comparing performance of:
Unshift with find vs Splice with findIndex vs unshift with Splice
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var data1 = []; for(i=0; i<10000; i++){data1.push(i);} var data2 = []; for(i=0; i<10000; i++){data2.push(i);} var data3 = []; for(i=0; i<10000; i++){data2.push(i);}
Tests:
Unshift with find
const rest = data1.filter(item => item !== 500); rest.unshift(data1.find(item => item == 500)); return rest;
Splice with findIndex
const cautelarPosition = data2.findIndex(item => item == 500); data2.splice(0, 0, data2.splice(cautelarPosition, 1)[0]); return data2;
unshift with Splice
const cautelarIndex = data3.findIndex(item => item == 500); data3.unshift(data3.splice(cautelarIndex, 1)[0]); return data3;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Unshift with find
Splice with findIndex
unshift with Splice
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 OPR/114.0.0.0
Browser/OS:
Opera 114 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Unshift with find
14520.5 Ops/sec
Splice with findIndex
42831.5 Ops/sec
unshift with Splice
2809841.8 Ops/sec
Related benchmarks:
Slice vs Splice delete 1000
Subarray - Splice vs Slice
Splice vs Spread vs Unshift to insert at beginning of array (fixed from slice)
Splice vs Shift to remove from the beginning
Using Splice vs Spread vs Unshift to insert at beginning of array
Comments
Confirm delete:
Do you really want to delete benchmark?