Last active
July 22, 2024 16:22
-
-
Save gsoulavy/74191670d0e4bd1e30dc862fec256702 to your computer and use it in GitHub Desktop.
This file contains 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
// 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