Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Remove by splice vs copyWithin
(version: 0)
In-place deletion of an element from an array.
Comparing performance of:
Delete by Splice vs Delete by copyWithin
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99] 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; } }
Tests:
Delete by Splice
deleteBySplice( array, 42 ); deleteBySplice( array, 0 ); deleteBySplice( array, 68 );
Delete by copyWithin
deleteByCopyWithin( array, 42 ); deleteByCopyWithin( array, 0 ); deleteByCopyWithin( array, 68 );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Delete by Splice
Delete by copyWithin
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0
Browser/OS:
Firefox 112 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Delete by Splice
1617989.0 Ops/sec
Delete by copyWithin
1604083.2 Ops/sec
Related benchmarks:
remove by splice vs filter array v4
remove by splice vs filter array v5
Remove by splice vs spread
Remove by splice vs copyWithin vs filter vs set.delete
Remove by splice vs copyWithin vs filter (numeric array)
Comments
Confirm delete:
Do you really want to delete benchmark?