-
-
Save x4d3/d41e8050caf0f7afbf10e618f64e7a22 to your computer and use it in GitHub Desktop.
Simple Ruby stopwatch
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
class Stopwatch | |
def initialize | |
@start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
end | |
def elapsed_time | |
Process.clock_gettime(Process::CLOCK_MONOTONIC) - @start_time | |
end | |
end | |
## Usage | |
sw = Stopwatch.new | |
sleep(2) | |
puts sw.elapsed_time | |
## Output | |
# 2.000997 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment