Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
concat vs spread vs push
(version: 1)
Comparing performance of:
concat vs spread vs push (spread) vs push (iterations)
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function generateID(length = 10) { const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let result = ''; const charactersLength = characters.length; for (let i = 0; i < length; i++) { // Generate a random index based on characters length const randomIndex = Math.floor(Math.random() * charactersLength); // Append the character at the random index to the result string result += characters[randomIndex]; } return result; } function createItem() { return { [generateID()]: 'value' }; }
Tests:
concat
let params = new Array(1000).fill('a').map(createItem); let other = new Array(1000).fill('a').map(createItem).concat(params);
spread
let params = new Array(1000).fill('a').map(createItem); let other = [...new Array(1000).fill('a').map(createItem), ...params];
push (spread)
let params = new Array(1000).fill('a').map(createItem); let other = new Array(1000).fill('a').map(createItem); other.push(...params);
push (iterations)
let params = new Array(1000).fill('a').map(createItem); let other = new Array(1000).fill('a').map(createItem); params.forEach(it => other.push(it));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
concat
spread
push (spread)
push (iterations)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
concat
694.2 Ops/sec
spread
707.0 Ops/sec
push (spread)
695.5 Ops/sec
push (iterations)
705.6 Ops/sec
Related benchmarks:
Lodash _.some vs _.includes vs array.find
get with insert : Array vs Map 3
Random ID generate
Object.create(null) vs {} vs Map() key access (heavy)
Split vs Spread (randomized)
lodash _.some vs Array.some
Mappers
.concat() is slow (immutable) vs .push() (mutation)
reduce: spreading acc vs mutating acc
Comments
Confirm delete:
Do you really want to delete benchmark?