Class: Timer

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

Class Method Summary collapse

Class Method Details

.elapsedTimeObject



20
21
22
# File 'lib/timer.rb', line 20

def self.elapsedTime
 humanize @time_taken
end

.humanize(ms) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/timer.rb', line 11

def self.humanize ms
  [[1000, :ms], [60, :secs], [60, :mins], [24, :hrs], [365, :days], [10000, :yrs]].map{ |count, name|
    if ms > 0
      ms, n = ms.divmod(count)
      "#{n.to_i} #{name}"
    end
  }.compact.reverse.join(' ')
end

.timeObject



24
25
26
# File 'lib/timer.rb', line 24

def self.time()
  elapsedTime
end

.timer(&block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/timer.rb', line 3

def self.timer(&block)
  start_time = Time.now
  result = block.call
  end_time = Time.now
  @time_taken = (end_time - start_time) * 1000
  result
end