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,
)
);