Sha256: 984cb0c41b67e45a93d1e854d235d0ccbaa69366cdc654ec814aa54da067df4f
Contents?: true
Size: 893 Bytes
Versions: 24
Compression:
Stored size: 893 Bytes
Contents
require "cabin/namespace" require "cabin/metrics/histogram" class Cabin::Metrics::Timer < Cabin::Metrics::Histogram # Start timing something. # # If no block is given # If a block is given, the execution of that block is timed. # public 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 # def time private def time_block(&block) start = Time.now block.call record(Time.now - start) end # def time_block class TimerContext public def initialize(&stop_callback) @start = Time.now @callback = stop_callback end public def stop duration = Time.now - @start @callback.call(duration) end # def stop end # class TimerContext end # class Cabin::Metrics::Timer
Version data entries
24 entries across 22 versions & 6 rubygems