class Timer
Public Class Methods
elapsedTime()
click to toggle source
# File lib/timer.rb, line 20 def self.elapsedTime humanize @time_taken end
humanize(ms)
click to toggle source
# 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
time()
click to toggle source
# File lib/timer.rb, line 24 def self.time() elapsedTime end
timer(&block)
click to toggle source
# 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