Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. const logPerformance = async (markName: string, func: () => Promise<any>) => {
  2. const startMarkerName = `${markName}-start`;
  3. const stopMarkerName = `${markName}-end`;
  4.  
  5. performance.mark(startMarkerName);
  6.  
  7. const response = await func();
  8.  
  9. performance.mark(stopMarkerName);
  10.  
  11. performance.measure(markName, startMarkerName, stopMarkerName);
  12. console.log(`${markName} : ${performance.getEntriesByName(markName)[0].duration.toFixed()} ms`);
  13.  
  14. performance.clearMarks(markName);
  15. performance.clearMeasures(startMarkerName);
  16. performance.clearMeasures(stopMarkerName);
  17.  
  18. return response;
  19. };
  20.  
  21. // Sample Usecase
  22. const response = await logPerformance('name', async () => {
  23. // perform some tasks
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement