Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array splice is slow
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
With Array.splice
4799048.0 Ops/sec
Tweaked version
15879785.0 Ops/sec
Tests:
With Array.splice
function arrayInsert(array, index, value) { array.splice(index, 0, value); } const months = ['Jan', 'March', 'April', 'June']; arrayInsert(months, 1, 'Feb');
Tweaked version
function arrayInsert(array, index, value) { let end = array.length; while (end > index) { const previousEnd = end - 1; array[end] = array[previousEnd]; end = previousEnd; } array[index] = value; } const months = ['Jan', 'March', 'April', 'June']; arrayInsert(months, 1, 'Feb');