Skip to content

Instantly share code, notes, and snippets.

@spac3unit
Created October 2, 2016 05:05
Show Gist options
  • Save spac3unit/2524d742422d7ebbea8475e481176788 to your computer and use it in GitHub Desktop.
Save spac3unit/2524d742422d7ebbea8475e481176788 to your computer and use it in GitHub Desktop.
function bench(method, args, description) {
var start, duration,
max = Number.MIN_VALUE,
min = Number.MAX_VALUE,
average = 0;
for(var i = 0; i< 10; i++) {
start = Date.now();
var index = method(args);
duration = Date.now() - start;
max = Math.max(max, duration);
min = Math.min(min, duration);
average += duration;
}
console.log('%s: average=%dms, min = %dms, max = %dms', description, average/10.0, min, max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment