Last active
October 4, 2018 09:07
-
-
Save ngerritsen/28f781d5b72aa933faf667e1edb9e00c to your computer and use it in GitHub Desktop.
Node hr timer
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 NS_PER_SEC = 1000000000; | |
const NS_PER_MS = 1000000; | |
function getTimer() { | |
const time = process.hrtime(); | |
return { | |
elapsed() { | |
const [seconds, nanoseconds] = process.hrtime(time); | |
return (seconds * NS_PER_SEC + nanoseconds) / NS_PER_MS; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment