class CheckpointTimer::Timer
Attributes
checkpoint_counter[R]
current_time[R]
log_all[R]
previous_time[R]
start_time[R]
Public Class Methods
new(log_all: false)
click to toggle source
# File lib/checkpoint_timer/timer.rb, line 14 def initialize(log_all: false) @log_all = log_all end
Public Instance Methods
checkpoint(logging: false, message: nil)
click to toggle source
@param message [String] @return [Fixnum]
# File lib/checkpoint_timer/timer.rb, line 26 def checkpoint(logging: false, message: nil) raise TimerNotStartedError unless start_time @previous_time = current_time set_current_time iterate_counter log_checkpoint(message) if logging || log_all? elapsed_time end
start()
click to toggle source
# File lib/checkpoint_timer/timer.rb, line 18 def start @checkpoint_counter = 0 @start_time = Time.now @current_time = start_time end
total_checkpoint_time()
click to toggle source
@return [Fixnum]
# File lib/checkpoint_timer/timer.rb, line 37 def total_checkpoint_time current_time - start_time end
Private Instance Methods
elapsed_time()
click to toggle source
@return [Fixnum]
# File lib/checkpoint_timer/timer.rb, line 59 def elapsed_time current_time - previous_time end
iterate_counter()
click to toggle source
# File lib/checkpoint_timer/timer.rb, line 50 def iterate_counter @checkpoint_counter += 1 end
log_all?()
click to toggle source
@return [Boolean]
# File lib/checkpoint_timer/timer.rb, line 64 def log_all? !!log_all end
log_checkpoint(message)
click to toggle source
@param message [String]
# File lib/checkpoint_timer/timer.rb, line 44 def log_checkpoint(message) puts "Checkpoint: #{checkpoint_counter}" puts message if message puts "Elapsed time since last checkpoint: #{format('%.3f', elapsed_time)}" end
set_current_time()
click to toggle source
# File lib/checkpoint_timer/timer.rb, line 54 def set_current_time @current_time = Time.now end