Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@deepal
Last active August 14, 2020 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepal/30a626c5e50f0419dd17833e250b1324 to your computer and use it in GitHub Desktop.
Save deepal/30a626c5e50f0419dd17833e250b1324 to your computer and use it in GitHub Desktop.
const startHrTime = () => {
if (typeof window !== 'undefined') return performance.now();
return process.hrtime();
}
const getHrTimeDiff = (start) => {
if (typeof window !== 'undefined') return performance.now() - start;
const [ts, tns] = (process.hrtime(start));
return ts * 1e3 + tns / 1e6;
}
console.log('start')
const start1 = startHrTime();
const outerTimer = setTimeout(() => {
const start2 = startHrTime();
console.log(`timer1: ${getHrTimeDiff(start1)}`)
setTimeout(() => {
const start3 = startHrTime();
console.log(`timer2: ${getHrTimeDiff(start2)}`)
setTimeout(() => {
const start4 = startHrTime();
console.log(`timer3: ${getHrTimeDiff(start3)}`)
setTimeout(() => {
const start5 = startHrTime();
console.log(`timer4: ${getHrTimeDiff(start4)}`)
setTimeout(() => {
const start6 = startHrTime();
console.log(`timer5: ${getHrTimeDiff(start5)}`)
setTimeout(() => {
const start7 = startHrTime();
console.log(`timer6: ${getHrTimeDiff(start6)}`)
setTimeout(() => {
const start8 = startHrTime();
console.log(`timer7: ${getHrTimeDiff(start7)}`)
setTimeout(() => {
console.log(`timer8: ${getHrTimeDiff(start8)}`)
})
})
})
})
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment