Skip to content

Instantly share code, notes, and snippets.

@nori3tsu
Last active August 29, 2015 14:13
Show Gist options
  • Save nori3tsu/23199da3c20bda39b401 to your computer and use it in GitHub Desktop.
Save nori3tsu/23199da3c20bda39b401 to your computer and use it in GitHub Desktop.
class StopWatch
def start
@start_time ||= Time.now
@stop_time = nil
self
end
def stop
@stop_time = Time.now
self
end
def reset
@start_time = nil
@stop_time = nil
self
end
def elapsed_millis
raise "not started." unless @start_time
if @stop_time
((@stop_time - @start_time) * 1000).to_i
else
((Time.now - @start_time) * 1000).to_i
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment