Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Remove by splice vs spliceIdx vs filter
Deletion of an element from an array.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.686 YaBrowser/23.9.5.686 Yowser/2.5 Safari/537.36
Browser:
Yandex Browser 23
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Delete by Splice
1088853.9 Ops/sec
Delete by Splice Index
1112789.4 Ops/sec
Delete by Filter
1191295.6 Ops/sec
HTML Preparation code:
<script> var array = ["m1c6kzws0iubt8g0zlsug14i","xalskr21dm5ke5wczew154s4i","hvbfe3uq3pmoehpilh4zpvi","ffr2btp9rihf3qce770ttke29","ymwh11qu16qwqn5vaafxhia4i","1l7rj49636ddmk3cbszitchaor","bg1njla9dvdkdlw9mbz1l9pb9","201y3ambt118dt7j7bxc6ry66r","hsgzqv2ex2j9j8znv3uzbyb9","k8tuq5ucdx1whgkdcby44pldi","2sjycnx525scxzfxfmwl7q4cxr"]; </script>
Script Preparation code:
/* these functions assume that only one element matches, so they do not loop! */ function deleteBySplice (array, element) { array.splice( array.indexOf( element ), 1 ); } function deleteBySpliceIdx (array, element) { array.splice( element, 1 ); } function deleteByFilter (array, element) { array = array.filter( el => el !== element ); }
Tests:
Delete by Splice
deleteBySplice( array, "2sjycnx525scxzfxfmwl7q4cxr" ); deleteBySplice( array, "m1c6kzws0iubt8g0zlsug14i" ); deleteBySplice( array, "1l7rj49636ddmk3cbszitchaor" );
Delete by Splice Index
deleteBySpliceIdx( array, 10 ); deleteBySpliceIdx( array, 0 ); deleteBySpliceIdx( array, 5 );
Delete by Filter
deleteByFilter( array, "2sjycnx525scxzfxfmwl7q4cxr" ); deleteByFilter( array, "m1c6kzws0iubt8g0zlsug14i" ); deleteByFilter( array, "1l7rj49636ddmk3cbszitchaor" );