class Cabin::Metrics::Timer

Public Instance Methods

time(&block) click to toggle source

Start timing something.

If no block is given If a block is given, the execution of that block is timed.

# File lib/cabin/metrics/timer.rb, line 11
def time(&block)
  return time_block(&block) if block_given?

  # Return an object we can .stop
  # Call record(...) when we stop.
  return TimerContext.new { |duration| record(duration) }
end

Private Instance Methods

time_block(&block) click to toggle source
# File lib/cabin/metrics/timer.rb, line 20
def time_block(&block)
  start = Time.now
  block.call
  record(Time.now - start)
end