Skip to content

Instantly share code, notes, and snippets.

@rostegg
Last active September 28, 2021 14:56
Show Gist options
  • Save rostegg/da547344a487c14e3f8fcba8a59dd630 to your computer and use it in GitHub Desktop.
Save rostegg/da547344a487c14e3f8fcba8a59dd630 to your computer and use it in GitHub Desktop.
Simple benchmarking
const benchmark = (func, input, iterations) => {
const start = performance.now()
for (let i = 0; i < iterations; i++) {
func(...input)
}
const finish = performance.now()
const time = finish - start
return {
time,
aproxOperation: (time/iterations)
}
}
function summary(a,b) {
return Math.sqrt(a*b)
}
benchmark(summary, [2,3], 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment