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.
9 10 11 |
# File 'lib/raykit/timer.rb', line 9 def initialize @start_time=Time.now end |
Instance Attribute Details
#start_time ⇒ Object
The time at which start occurred
7 8 9 |
# File 'lib/raykit/timer.rb', line 7 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
24 25 26 27 |
# File 'lib/raykit/timer.rb', line 24 def self.get_elapsed_str(elapsed,pad=0) #"[" + "%.0f" % (elapsed) + "s]".ljust(pad) "%.0f" % (elapsed) + "s".ljust(pad) end |
Instance Method Details
#elapsed ⇒ Object
The elapsed time, in seconds, since the timer started
14 15 16 |
# File 'lib/raykit/timer.rb', line 14 def elapsed return Time.now-@start_time end |
#elapsed_str(pad = 0) ⇒ Object
The elapsed time, in seconds, as a formatted string
19 20 21 |
# File 'lib/raykit/timer.rb', line 19 def elapsed_str(pad=0) Timer.get_elapsed_str(elapsed,pad) end |