Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
Created November 28, 2023 08:27
Show Gist options
  • Save hi-ogawa/6b5a2b1a72fc34174c4fcf297fb528aa to your computer and use it in GitHub Desktop.
Save hi-ogawa/6b5a2b1a72fc34174c4fcf297fb528aa to your computer and use it in GitHub Desktop.
wrapConsoleTimeAsync.ts
function wrapConsoleTimeAsync<F extends (...args: any[]) => any>(f: F) {
const wrapper = async function (this: any, ...args: any[]) {
const id = Math.random().toString(36).slice(2).padStart(12, "0");
const label = `${f.name}:${id}`;
globalThis.console.time(label);
try {
return await f.apply(this, args);
} finally {
globalThis.console.timeEnd(label);
}
}
return wrapper as F;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment