Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.splice + Array.indexOf vs Array.filter
(version: 1)
Test a speed difference between these 2 approaches
Comparing performance of:
Splice It vs filter It
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script> const i1 = {}; const i2 = {}; const i3 = {}; const i4 = {}; const i5 = {}; const i6 = {}; const i7 = {}; const i8 = {}; const i9 = {}; const i10 = {}; const array = [i1, i2, i3, i4, i5, i6, i7, i8, i9, i10]; </script>
Script Preparation code:
function spliceIt(array, element){ const index = array.indexOf(element); if (index > -1) array.splice(index, 1); } function filterIt(array, element){ array = array.filter(el => el !== element); }
Tests:
Splice It
spliceIt(array, i5);
filter It
filterIt(array, i5);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Splice It
filter It
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Splice It
54478116.0 Ops/sec
filter It
20303112.0 Ops/sec
Related benchmarks:
Remove by splice vs spliceIdx vs filter
Array.splice vs Array.filter
Array.splice with indexOf vs Array.filter
JS filter vs splice +indexOf
Array.toSpliced vs Array.filter
Remove by splice vs filter with a known index
Array.splice vs Array.filter V223
splice or filter
Array.splice + indexOf vs Array.filter
Comments
Confirm delete:
Do you really want to delete benchmark?