Class: Raykit::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/raykit/timer.rb

Overview

Provides functionality to record the time execution times

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

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_timeObject

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

#elapsedObject

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