Skip to content

Instantly share code, notes, and snippets.

@richardscarrott
Created February 6, 2020 16:30
Show Gist options
  • Save richardscarrott/a595cd3e3386a721a0feb3895c9d4de9 to your computer and use it in GitHub Desktop.
Save richardscarrott/a595cd3e3386a721a0feb3895c9d4de9 to your computer and use it in GitHub Desktop.
High precision time
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