Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Unshift vs concat
We can add elements to the beginning of array using both, let's find out which is faster. Unshift also mutates the array. Concat does not, so that would be preferable.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0
Browser:
Firefox 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Unshift
184K/s
Concat
35/s
View exact numbers
Test name
Executions per second
✓
Unshift
184,052 Ops/sec
Concat
35 Ops/sec
Script Preparation code:
var arr = [1, 3, 5, 11, 13];
Tests:
Unshift
arr.unshift(4,5)
Concat
[4,5].concat(arr);