class StopWatch
Public Class Methods
measure(&block)
click to toggle source
Instantiate class and call {#measure}
# File lib/spinning_cursor/stop_watch.rb, line 6 def self.measure(&block) sw = self.new sw.measure &block end
Public Instance Methods
elapsed_time()
click to toggle source
Returns the elapsed time @note If the timer has not yet stopped, the time elapsed from the start of
the timer till `Time.now` is returned
# File lib/spinning_cursor/stop_watch.rb, line 53 def elapsed_time time_now = Time.now (@stop_time || time_now ) - (@start_time || time_now) end
inspect()
click to toggle source
# File lib/spinning_cursor/stop_watch.rb, line 60 def inspect puts "#{old_inspect} #{{:elapsed_time => elapsed_time}}" end
Also aliased as: old_inspect
measure() { || ... }
click to toggle source
Measures the time taken to process the passed block and returns the measurment (see {timing})
# File lib/spinning_cursor/stop_watch.rb, line 15 def measure(&block) start yield stop timing end
reset()
click to toggle source
Resets timer
# File lib/spinning_cursor/stop_watch.rb, line 44 def reset @start_time = @stop_time = nil end
start()
click to toggle source
Starts timer
# File lib/spinning_cursor/stop_watch.rb, line 25 def start @start_time = Time.now @stop_time = nil self end
stop()
click to toggle source
Stops timer
# File lib/spinning_cursor/stop_watch.rb, line 34 def stop if @start_time @stop_time = Time.now end self end
timing()
click to toggle source
Returns the measurement in a hash containing
-
the start time
-
the stop time
-
the total elapsed time
# File lib/spinning_cursor/stop_watch.rb, line 70 def timing { :start_time => @start_time, :stop_time => @stop_time, :elapsed_time => elapsed_time } end