Skip to content

Instantly share code, notes, and snippets.

@x4d3
Forked from ikenna/stopwatch.rb
Last active October 25, 2018 13:10
Show Gist options
  • Save x4d3/d41e8050caf0f7afbf10e618f64e7a22 to your computer and use it in GitHub Desktop.
Save x4d3/d41e8050caf0f7afbf10e618f64e7a22 to your computer and use it in GitHub Desktop.
Simple Ruby stopwatch
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