Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Last active March 24, 2020 06:30
Show Gist options
  • Save Sawtaytoes/98bb41bd16ab0f91fccae1a07691e6b8 to your computer and use it in GitHub Desktop.
Save Sawtaytoes/98bb41bd16ab0f91fccae1a07691e6b8 to your computer and use it in GitHub Desktop.
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