Created
March 8, 2019 12:55
-
-
Save ivan-marquez/f3f62977ea308d62964c5e4904ebc638 to your computer and use it in GitHub Desktop.
monitor the processing time of any functions
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
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