Class: Stopwatch

Inherits:
Object
  • Object
show all
Includes:
NumTools
Defined in:
lib/walltime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NumTools

define_component, #random_between

Instance Attribute Details

#roundvalsObject (readonly)

Returns the value of attribute roundvals.



33
34
35
# File 'lib/walltime.rb', line 33

def roundvals
  @roundvals
end

#t1Object (readonly)

Returns the value of attribute t1.



33
34
35
# File 'lib/walltime.rb', line 33

def t1
  @t1
end

#t2Object (readonly)

Returns the value of attribute t2.



33
34
35
# File 'lib/walltime.rb', line 33

def t2
  @t2
end

Instance Method Details



57
58
59
60
# File 'lib/walltime.rb', line 57

def print_stats
  round = round_to(@t2 - @t1, 2)
  puts "Start: #{Time.at(@t1)} Finish: #{Time.at(@t2)} Total time: #{round}"
end

#record(round) ⇒ Object



53
54
55
# File 'lib/walltime.rb', line 53

def record(round)
  @roundvals << round
end

#start(&block) ⇒ Object



71
72
73
74
# File 'lib/walltime.rb', line 71

def start(&block)
  watch('start')
  block.call
end

#stop(&block) ⇒ Object



76
77
78
79
# File 'lib/walltime.rb', line 76

def stop(&block)
  block.call
  watch('stop')
end

#watch(method) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/walltime.rb', line 62

def watch(method)
  if method == "start"
    @t1 = timestamp
  elsif method == "stop"
    @t2 = timestamp
    intervalh
  end
end