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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0
Browser:
Chrome 122
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Array.prototype.concat
844K/s
Push Spread
681K/s
Push Apply
596K/s
Push Loop
106K/s
spread operator
93K/s
View exact numbers
Test name
Executions per second
✓
Array.prototype.concat
843,862 Ops/sec
Push Spread
680,930 Ops/sec
Push Apply
595,711 Ops/sec
Push Loop
105,527 Ops/sec
spread operator
92,860 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;