Last active
March 24, 2020 06:30
-
-
Save Sawtaytoes/98bb41bd16ab0f91fccae1a07691e6b8 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 performanceTest = (func, iterations) => { | |
const before = performance.now() | |
for(let i = 0; i < iterations; i++) { | |
func() | |
} | |
const after = performance.now() | |
const elapsed = after - before | |
return `${elapsed.toFixed(6)}ms` | |
} | |
const iterations = 10000000 // 10 million | |
console.info(`${iterations.toLocaleString()} iterations.`) | |
const timings = { | |
'() => {}': ( | |
performanceTest( | |
() => {}, | |
iterations, | |
) | |
), | |
'Function.prototype': ( | |
performanceTest( | |
Function.prototype, | |
iterations, | |
) | |
), | |
} | |
console.info( | |
JSON.stringify( | |
timings, | |
null, | |
4, | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment