Last active
September 28, 2021 14:56
-
-
Save rostegg/da547344a487c14e3f8fcba8a59dd630 to your computer and use it in GitHub Desktop.
Simple benchmarking
This file contains hidden or 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 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