Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. /**
  2. * Measures the runtime of given callable function
  3. * Second argument is optional, and puts an identifier string in front of console.log
  4. */
  5. function timePerformance(callable) {
  6. // Identifier string to differentiate timings
  7. var identifier = arguments[1] || 'Time';
  8.  
  9. // Start time
  10. var t0 = performance.now();
  11.  
  12. // Run the function, log any results
  13. var result = callable();
  14. if(result) {
  15. console.log(result);
  16. }
  17.  
  18. // End time
  19. var t1 = performance.now();
  20.  
  21. // Log out the timing
  22. var runtime = (t1 - t0).toFixed(3);
  23. console.log(identifier + ": " + runtime + " milliseconds");
  24.  
  25. return runtime;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement