Last active
November 29, 2018 04:07
-
-
Save anchan828/6217e008f8276d576c73b90930e50e18 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
import { performance } from 'perf_hooks'; | |
export function timerify<T = any>() { | |
return function( | |
target: any, | |
propertyKey: string, | |
descriptor: TypedPropertyDescriptor<any>, | |
) { | |
const oldDescriptor = descriptor.value; | |
if (!oldDescriptor) { | |
console.log(`oldDescriptor is undefined`); | |
return; | |
} | |
descriptor.value = function(...args: any[]) { | |
const fnResult = performance.timerify(oldDescriptor.bind(this)); | |
return fnResult.apply(this, args); | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment