Last active
March 15, 2022 20:44
-
-
Save deepal/871151b803badaef4ad614795e09c2df 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
setFakeTime(); | |
const startTimeToD = Date.now(); // set startTime with time-of-day clock | |
const startTimeMon = performance.now(); // set startTime with monotonic clock | |
setImmediate(() => { | |
correctTimeNTP(); // synchronise the clock | |
}); | |
await doSomething(); | |
const endTimeToD = Date.now(); // set endTime with time-of-day clock | |
const endTimeMon = performance.now(); // set endTime with monotonic clock | |
const durationToD = endTimeToD - startTimeToD; | |
const durationMon = endTimeMon - startTimeMon; | |
const error = (durationToD - durationMon) / 1000; | |
console.log(`Duration measured by time-of-day clock\t: ${durationToD}ms`); | |
console.log(`Duration measured by monotonic clock\t: ${durationMon}ms`); | |
console.log(`Error: ${error.toFixed(3)}s`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment