Class: Raykit::Timer
- Inherits:
-
Object
- Object
- Raykit::Timer
- Defined in:
- lib/raykit/timer.rb
Overview
Provides functionality to record the time execution times
Instance Attribute Summary collapse
-
#start_time ⇒ Object
The time at which start occurred.
Class Method Summary collapse
-
.get_elapsed_str(elapsed, pad = 0) ⇒ Object
Converts a time span in seconds to a formatted string.
Instance Method Summary collapse
-
#elapsed ⇒ Object
The elapsed time, in seconds, since the timer started.
-
#elapsed_str(pad = 0) ⇒ Object
The elapsed time, in seconds, as a formatted string.
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
11 12 13 |
# File 'lib/raykit/timer.rb', line 11 def initialize @start_time = Time.now end |
Instance Attribute Details
#start_time ⇒ Object
The time at which start occurred
9 10 11 |
# File 'lib/raykit/timer.rb', line 9 def start_time @start_time end |
Class Method Details
.get_elapsed_str(elapsed, pad = 0) ⇒ Object
Converts a time span in seconds to a formatted string
26 27 28 29 |
# File 'lib/raykit/timer.rb', line 26 def self.get_elapsed_str(elapsed, pad = 0) # "[" + "%.0f" % (elapsed) + "s]".ljust(pad) format("%.0f", elapsed) + "s".ljust(pad) end |
Instance Method Details
#elapsed ⇒ Object
The elapsed time, in seconds, since the timer started
16 17 18 |
# File 'lib/raykit/timer.rb', line 16 def elapsed Time.now - @start_time end |
#elapsed_str(pad = 0) ⇒ Object
The elapsed time, in seconds, as a formatted string
21 22 23 |
# File 'lib/raykit/timer.rb', line 21 def elapsed_str(pad = 0) Timer.get_elapsed_str(elapsed, pad) end |