Skip to content

Instantly share code, notes, and snippets.

@paitonic
Last active April 5, 2016 12:28
Show Gist options
  • Save paitonic/1636687060575ad2e970dfe9b14e66a1 to your computer and use it in GitHub Desktop.
Save paitonic/1636687060575ad2e970dfe9b14e66a1 to your computer and use it in GitHub Desktop.
measure function execution
function perf(self, func) {
// everything is argument except for 'self' and 'func'
var args = Array.prototype.slice.call(arguments, 2, arguments.length);
var t1 = performance.now();
func.apply(self, args);
var t2 = performance.now();
var t = t2 - t1;
return t.toFixed(2) + 'ms' + ', ' + (t / 1000).toFixed(2) + 's';
}
// usage
// perf(null, f, 1, 2, 3);
// perf(obj, obj.doSomething, 1, 2, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment