Created
July 7, 2021 08:30
-
-
Save iolathief108/79093ddf09bed8341aede4775c7c4bf2 to your computer and use it in GitHub Desktop.
Javascript small benchmark script
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
function benchmark(method) { | |
const start = +(new Date); | |
const count = method(); | |
const end = +(new Date); | |
const sec = ((end - start) / 1000) % 60; | |
console.log(`Processed in under: ` + sec + 's'); | |
if (count && typeof count === 'number') { | |
console.log('Performance of ' + Math.round(count / sec) + ' op/s'); | |
} | |
} | |
// Usage | |
function operation() { | |
let count = 0; | |
while (count < 800000) { | |
yourFunc('simple_400x200q40.webp'); | |
count++; | |
} | |
return count; | |
} | |
benchmark(operation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment