Created
September 28, 2023 15:49
-
-
Save sibelius/185ff86a0821b49996ab2d1eb2a8df0d to your computer and use it in GitHub Desktop.
timeSpan
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
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; | |
}; |
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 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