Created
February 6, 2020 16:30
-
-
Save richardscarrott/a595cd3e3386a721a0feb3895c9d4de9 to your computer and use it in GitHub Desktop.
High precision 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 work = () => { | |
for (let i = 0; i < 1000000; i++) {} | |
}; | |
const start = process.hrtime.bigint(); | |
work(); | |
const end = process.hrtime.bigint(); | |
console.log( | |
`Benchmark took ${Number(end - start) / 1000 / 1000 / 1000} seconds` | |
); | |
console.log(`Benchmark took ${Number(end - start) / 1000 / 1000} milliseconds`); | |
console.log(`Benchmark took ${Number(end - start) / 1000} microseconds`); | |
console.log(`Benchmark took ${Number(end - start)} nanoseconds`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment