Skip to content

Instantly share code, notes, and snippets.

@iolathief108
Created July 7, 2021 08:30
Embed
What would you like to do?
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