HTML Preparation code:
AخA
 
1
<script>
2
  var array = [];
3
  for(let i = 0; i < 1000; i++) {array[i] = i;}
4
</script>
Script Preparation code:
x
 
/* 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 );
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Delete by Splice
    Delete by copyWithin
    Delete by Filter

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 days ago)
Mozilla/5.0 (X11; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0
Firefox 137 on Linux
View result in a separate tab
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