module SSO::Benchmarking

Helper to log results of benchmarks.

Public Instance Methods

benchmark(name: nil, metric: nil, &block) click to toggle source
# File lib/sso/benchmarking.rb, line 7
def benchmark(name: nil, metric: nil, &block)
  return unless block_given?
  result = nil
  seconds = Benchmark.realtime do
    result = block.call
  end
  milliseconds = (seconds * 1000).round
  debug { "#{name || metric || 'Benchmark'} took #{milliseconds}ms" }
  timing key: metric, value: milliseconds if metric
  result
end