Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Array concat vs spread vs push spread, loop, apply (bigger cases)
Compare the new ES6 spread operator with the traditional concat() method and push
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/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Array.prototype.concat
3.3M/s
Push Apply
1.6M/s
Push Spread
1.6M/s
Push Loop
1.4M/s
spread operator
1.2M/s
View exact numbers
Test name
Executions per second
✓
Array.prototype.concat
3,281,684 Ops/sec
Push Apply
1,649,727 Ops/sec
Push Spread
1,641,154 Ops/sec
Push Loop
1,377,948 Ops/sec
spread operator
1,184,966 Ops/sec
Script Preparation code:
var subarrs = [ [ "hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7,"hello", true, 7 ], [ "yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27,"yes", "no", "maybe", false, 27 ], [ 16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest",16, "I", "wonder", "what", "will", "be", "fastest" ] ];
Tests:
Array.prototype.concat
var other = [ 1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3 ] for (var len = subarrs.length, i = 0; i < len; i++){ other = other.concat(subarrs[i]); } return other;
spread operator
var other = [ 1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3 ] for (var len = subarrs.length, i = 0; i < len; i++){ other = [ ...other, ...subarrs[i] ] } return other;
Push Spread
var other = [ 1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3 ] for (var len = subarrs.length, i = 0; i < len; i++){ other.push(...subarrs[i]); } return other;
Push Apply
var other = [ 1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3 ] for (var len = subarrs.length, i = 0; i < len; i++){ other.push.apply(other, subarrs[i]); } return other;
Push Loop
var other = [ 1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3,1, 2, 3 ] for (var len = subarrs.length, i = 0; i < len; i++){ for (var jarr = subarrs[i], jen = jarr.length, j = 0; j < jen; j++){ other.push(jarr[j]); } } return other;