Created
May 14, 2021 17:13
-
-
Save Sinequanonh/22cefe85caf2571dc597a6e98f29ab0b to your computer and use it in GitHub Desktop.
Measure promise time
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
const measurePromise = (p) => new Promise(async (resolve, reject) => { | |
const startHrTime = process.hrtime(); | |
const res = await p; | |
const elapsedHrTime = process.hrtime(startHrTime); | |
const elapsedTimeInMs = Math.round(elapsedHrTime[0] * 1000 + elapsedHrTime[1] / 1e6); | |
console.log('elapsedTime', elapsedTimeInMs / 1000 + 's'); | |
resolve(res); | |
}); | |
module.exports = measurePromise; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment