Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Created July 2, 2012 23:15
Show Gist options
  • Save mkuklis/3036302 to your computer and use it in GitHub Desktop.
Save mkuklis/3036302 to your computer and use it in GitHub Desktop.
profilejs
function profile(methods, ctx) {
ctx = ctx || this;
for (var i = 0, l = methods.length; i < l; i++) {
(function(name) {
var method = ctx[name];
ctx[name] = function () {
console.time(name);
method.apply(this, arguments);
console.timeEnd(name);
}
})(methods[i]);
}
}
// example
var obj = {
test1: function (name) {
console.log('test1 ' + name);
},
test2: function () {
console.log('test2');
}
};
profile(["test1", "test2"], obj);
obj.test1("hello");
obj.test2();
//test1 hello
//test1: 10ms
//test2
//test2: 1ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment