class Attestify::Timer

A timer for keeping track of the timing of code.

Attributes

duration[R]
result[R]

Public Class Methods

new() { || ... } click to toggle source
# File lib/attestify/timer.rb, line 6
def initialize
  start_time = Time.new
  @result = yield
ensure
  end_time = Time.new
  @duration = end_time - start_time
end
time() { || ... } click to toggle source
# File lib/attestify/timer.rb, line 14
def self.time
  Timer.new do
    yield
  end
end

Public Instance Methods

to_s() click to toggle source
# File lib/attestify/timer.rb, line 20
def to_s
  if duration < 1.0
    format("%.1f milliseconds", duration * 1000.0)
  elsif duration < 60.0
    format("%.1f seconds", duration)
  else
    format("%.2f minutes", duration / 60.0)
  end
end