-
-
Save piglovesyou/25227aafe37c1f136f746e9803c9e3eb to your computer and use it in GitHub Desktop.
JavaScript speed comparison: [...array] vs. array.concat()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const a = Array.from(Array(1000_000)).map((_, i) => i); | |
const b = Array.from(Array(1000_000)).map((_, i) => i); | |
const times = 1000; | |
console.time("spread"); | |
for (let i = 0; i < times; i++) { | |
const c = [...a, ...b]; | |
c.length; | |
} | |
console.timeEnd("spread"); | |
console.time("concat"); | |
for (let i = 0; i < times; i++) { | |
const d = a.concat(b); | |
d.length; | |
} | |
console.timeEnd("concat"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Node v17.8.0