Created
April 23, 2019 04:03
-
-
Save Himenon/3bb8399f833b1e15d697cc8344b1024e to your computer and use it in GitHub Desktop.
This file contains 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(100000).fill(Math.random()); | |
const b = Array(100000).fill(Math.random()); | |
const benchmark = (func, repeat) => { | |
const result = []; | |
Array(repeat) | |
.fill(1) | |
.map(() => { | |
const start = window.performance.now(); | |
func(); | |
const end = window.performance.now(); | |
const time = end - start; | |
result.push(time); | |
}); | |
const average = result.reduce((total, t) => total + t) / repeat; | |
console.table({ try: repeat, average }); | |
}; | |
benchmark(() => [...a, ...b], 1000); | |
benchmark(() => a.concat(b), 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment