Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.concat() is slow (immutable) vs .push() (mutation)
(version: 1)
Comparing performance of:
spread vs assign key
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; } const data = new Array(100).fill('a').map(() => ({ key: generateID(), value: 'value' }));
Tests:
spread
const result = data.reduce((acc, item) => { return { ...acc, [item.key]: item.value, }; }, {});
assign key
const result = data.reduce((acc, item) => { acc[item.key] = item.value; return acc; }, {});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
spread
assign key
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/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
spread
5190.5 Ops/sec
assign key
207778.0 Ops/sec
Related benchmarks:
Lodash _.some vs _.includes vs array.find
Lodash vs vanila 2
get with insert : Array vs Map 3
toLowerCase() Sorting
IndexOf vs Includes vs lodash includes vs dictionary with large array
lodash _.some vs Array.some
Better set.has vs array.includes
Mappers
reduce: spreading acc vs mutating acc
Comments
Confirm delete:
Do you really want to delete benchmark?