Skip to content

Instantly share code, notes, and snippets.

@anchan828
Last active November 29, 2018 04:07
Show Gist options
  • Save anchan828/6217e008f8276d576c73b90930e50e18 to your computer and use it in GitHub Desktop.
Save anchan828/6217e008f8276d576c73b90930e50e18 to your computer and use it in GitHub Desktop.
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