Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created September 28, 2023 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibelius/185ff86a0821b49996ab2d1eb2a8df0d to your computer and use it in GitHub Desktop.
Save sibelius/185ff86a0821b49996ab2d1eb2a8df0d to your computer and use it in GitHub Desktop.
timeSpan
import convertHrtime from 'convert-hrtime';
export const timeSpan = () => {
const start = process.hrtime();
const end = (type) => convertHrtime(process.hrtime(start))[type];
const returnValue = () => end('milliseconds');
returnValue.rounded = () => Math.round(end('milliseconds'));
returnValue.seconds = () => end('seconds');
returnValue.nanoseconds = () => end('nanoseconds');
return returnValue;
};
const end = timeSpan();
await fn();
console.log(end());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment