Last active
March 18, 2018 13:35
-
-
Save jechasteen/f60650de3956e45e69972eebeb59e8d0 to your computer and use it in GitHub Desktop.
Times a function using a callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For use in Node.js | |
//const { performance } = require('perf_hooks') | |
function funcTimer(callback){ | |
performance.mark('A') | |
var callbackReturn = callback(); | |
performance.mark('B') | |
performance.measure('A->B', 'A', 'B') | |
const measure = performance.getEntriesByName('A->B')[0] | |
console.log(arguments.callee.name, 'execution took:', measure.duration, 'ms') | |
return callbackReturn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment