Class: Stopwatch
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from NumTools
define_component, #random_between
Instance Attribute Details
#roundvals ⇒ Object
Returns the value of attribute roundvals.
33
34
35
|
# File 'lib/walltime.rb', line 33
def roundvals
@roundvals
end
|
#t1 ⇒ Object
Returns the value of attribute t1.
33
34
35
|
# File 'lib/walltime.rb', line 33
def t1
@t1
end
|
#t2 ⇒ Object
Returns the value of attribute t2.
33
34
35
|
# File 'lib/walltime.rb', line 33
def t2
@t2
end
|
Instance Method Details
#print_stats ⇒ Object
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
|