Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Remove by splice vs copyWithin
In-place deletion of an element from an array.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 120
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
Test name
Executions per second
Delete by Splice
1787097.9 Ops/sec
Delete by copyWithin
1784608.0 Ops/sec
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 );