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 (Macintosh; Intel Mac OS X 10.15; rv:152.0) Gecko/20100101 Firefox/152.0
Browser:
Firefox 152
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one month ago
Benchmark engine:
Benchmark.js
Unshift
419K/s
Concat
157/s
View exact numbers
Test name
Executions per second
✓
Unshift
418,842 Ops/sec
Concat
157 Ops/sec
Script Preparation code:
var arr = [1, 3, 5, 11, 13];
Tests:
Unshift
arr.unshift(4,5)
Concat
[4,5].concat(arr);