Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Measures the runtime of given callable function
- * Second argument is optional, and puts an identifier string in front of console.log
- */
- function timePerformance(callable) {
- // Identifier string to differentiate timings
- var identifier = arguments[1] || 'Time';
- // Start time
- var t0 = performance.now();
- // Run the function, log any results
- var result = callable();
- if(result) {
- console.log(result);
- }
- // End time
- var t1 = performance.now();
- // Log out the timing
- var runtime = (t1 - t0).toFixed(3);
- console.log(identifier + ": " + runtime + " milliseconds");
- return runtime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement