Last active
August 14, 2020 01:52
-
-
Save deepal/30a626c5e50f0419dd17833e250b1324 to your computer and use it in GitHub Desktop.
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 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