Skip to content

Instantly share code, notes, and snippets.

@ngerritsen
Last active October 4, 2018 09:07
Show Gist options
  • Save ngerritsen/28f781d5b72aa933faf667e1edb9e00c to your computer and use it in GitHub Desktop.
Save ngerritsen/28f781d5b72aa933faf667e1edb9e00c to your computer and use it in GitHub Desktop.
Node hr timer
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