Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Remove by splice vs copyWithin vs filter (numeric array)
Deletion of an element from an array.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0
Browser:
Firefox 137
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Delete by Splice
283760.3 Ops/sec
Delete by copyWithin
284425.8 Ops/sec
Delete by Filter
41340.5 Ops/sec
HTML Preparation code:
<script> var array = []; for(let i = 0; i < 1000; i++) {array[i] = i;} </script>
Script Preparation code:
/* these functions assume that only one element matches, so they do not loop! */ function deleteBySplice (array, element) { var index = array.indexOf( element ); if (index !== -1) { array.splice( index, 1 ); } } function deleteByCopyWithin (array, element) { var index = array.indexOf( element ); if (index !== -1) { array.copyWithin( index, index + 1 ); --array.length; } } function deleteByFilter (array, element) { array = array.filter( el => el !== element ); }
Tests:
Delete by Splice
deleteBySplice( array, 21 ); deleteBySplice( array, 304 ); deleteBySplice( array, 777 );
Delete by copyWithin
deleteByCopyWithin( array, 21 ); deleteByCopyWithin( array, 304 ); deleteByCopyWithin( array, 777 );
Delete by Filter
deleteByFilter( array, 21 ); deleteByFilter( array, 304 ); deleteByFilter( array, 777 );