Skip to content

Instantly share code, notes, and snippets.

@torgeir
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torgeir/eb8f62b5c83c878ac8cf to your computer and use it in GitHub Desktop.
Save torgeir/eb8f62b5c83c878ac8cf to your computer and use it in GitHub Desktop.
es6 proxy profile method example
function profile (o) {
for (var key in o) {
var field = o[key];
if (typeof field == 'function') {
o[key] = Proxy.createFunction({},
// call
function () {
var before = new Date;
var res = field.apply(o, arguments);
var spent = new Date - before;
console.log('time spent calling "%s": %sms', key, spent);
return res;
},
// new
function () {
});
}
}
}
var o = {
doit: function () {
var i = 100000000;
while (i--);
return 42;
}
}
profile(o);
console.log(o.doit());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment