Created
May 19, 2016 16:56
-
-
Save olange/379bde69c188597a559579dbd9c94f24 to your computer and use it in GitHub Desktop.
Measuring a duration of execution in Node.js
This file contains hidden or 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
## | |
# Utility function to measure time intervals. Polymorphic return value: | |
# | |
# * returns either the current high-resolution real time, given no argument; | |
# * or the time elapsed since a given high-resolution real time, that was | |
# retrieved from a previous call to this function. | |
# | |
# Usage: | |
# t0 = hrtime() | |
# duration = hrtime( t0) # expressed in milliseconds | |
# | |
# See also: | |
# [Node.js API › process.hrtime()](https://nodejs.org/api/process.html#process_process_hrtime) | |
# | |
hrtime = (since) -> | |
return process.hrtime() unless since? | |
end = process.hrtime( since) | |
Math.round(( end[ 0] * 1e3) + ( end[ 1] / 1e6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment