Last active
April 5, 2016 12:28
-
-
Save paitonic/1636687060575ad2e970dfe9b14e66a1 to your computer and use it in GitHub Desktop.
measure function execution
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 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