Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const logPerformance = async (markName: string, func: () => Promise<any>) => {
- const startMarkerName = `${markName}-start`;
- const stopMarkerName = `${markName}-end`;
- performance.mark(startMarkerName);
- const response = await func();
- performance.mark(stopMarkerName);
- performance.measure(markName, startMarkerName, stopMarkerName);
- console.log(`${markName} : ${performance.getEntriesByName(markName)[0].duration.toFixed()} ms`);
- performance.clearMarks(markName);
- performance.clearMeasures(startMarkerName);
- performance.clearMeasures(stopMarkerName);
- return response;
- };
- // Sample Usecase
- const response = await logPerformance('name', async () => {
- // perform some tasks
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement