Skip to content

Instantly share code, notes, and snippets.

@jechasteen
Last active March 18, 2018 13:35
Show Gist options
  • Save jechasteen/f60650de3956e45e69972eebeb59e8d0 to your computer and use it in GitHub Desktop.
Save jechasteen/f60650de3956e45e69972eebeb59e8d0 to your computer and use it in GitHub Desktop.
Times a function using a callback
// 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