Skip to content

Instantly share code, notes, and snippets.

@ivan-marquez
Created March 8, 2019 12:55
Show Gist options
  • Save ivan-marquez/f3f62977ea308d62964c5e4904ebc638 to your computer and use it in GitHub Desktop.
Save ivan-marquez/f3f62977ea308d62964c5e4904ebc638 to your computer and use it in GitHub Desktop.
monitor the processing time of any functions
module.exports = (start, tag) => {
if (start) {
let endTime = process.hrtime(start)
let duration = parseInt((endTime[0] * 1000) + (endTime[1] / 1000000))
console.log(`Duration for ${tag}: ${duration} msec`)
} else {
return process.hrtime()
}
}
/*
* The purpose of this module is to monitor the processing time of our functions.
* For more info on `process.hrtime()`:
* https://nodejs.org/api/process.html#process_process_hrtime_time
*
* Ex:
* const monitor = require(./monitor)
*
* function bar () {
* var start = monitor()
* foreach () {
* ...
* }
* monitor(start, 'bar')
* }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment