Skip to content

Instantly share code, notes, and snippets.

@iolathief108
Created July 7, 2021 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iolathief108/79093ddf09bed8341aede4775c7c4bf2 to your computer and use it in GitHub Desktop.
Save iolathief108/79093ddf09bed8341aede4775c7c4bf2 to your computer and use it in GitHub Desktop.
Javascript small benchmark script
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