Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. const now = () => Date.now();
  2.  
  3. const report = {};
  4.  
  5. const p = wrappedFunction => {
  6. report[wrappedFunction.name] = { min: 0, max: 0, avg: 0, callCount: 0 };
  7.  
  8. const times = [];
  9. return (...args) => {
  10. const start = performance.now();
  11. const returnValue = wrappedFunction(...args);
  12. const end = performance.now();
  13.  
  14. report[wrappedFunction.name].callCount++;
  15. const elapsed = end - start;
  16. times.push(elapsed);
  17.  
  18. report[wrappedFunction.name].min = Math.min.apply(undefined, times);
  19. report[wrappedFunction.name].max = Math.max.apply(undefined, times);
  20. report[wrappedFunction.name].avg = times.reduce((p, c) => p + c, 0) / times.length;
  21.  
  22. return returnValue;
  23. };
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement