Skip to content

Instantly share code, notes, and snippets.

@gsoulavy
Last active July 22, 2024 16:22
Show Gist options
  • Save gsoulavy/74191670d0e4bd1e30dc862fec256702 to your computer and use it in GitHub Desktop.
Save gsoulavy/74191670d0e4bd1e30dc862fec256702 to your computer and use it in GitHub Desktop.
// usage: @time
function time(target: any, context: ClassMethodDecoratorContext): any {
const originalMethod = target;
const resultMethod = async function (this: any, ...arg: any[]) {
const start = performance.now();
try {
return await originalMethod.apply(this, arg);
} catch (error) {
console.log(error);
throw error;
} finally {
const end = performance.now();
console.log(`${String(context.name)} took ${end - start}`);
}
};
return resultMethod;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment