Skip to content

Instantly share code, notes, and snippets.

@Sinequanonh
Created May 14, 2021 17:13
Show Gist options
  • Save Sinequanonh/22cefe85caf2571dc597a6e98f29ab0b to your computer and use it in GitHub Desktop.
Save Sinequanonh/22cefe85caf2571dc597a6e98f29ab0b to your computer and use it in GitHub Desktop.
Measure promise time
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