Module: SSO::Benchmarking

Overview

Helper to log results of benchmarks.

Instance Method Summary collapse

Methods included from Meter

#caller_name, #metric, #timing, #track

Methods included from Logging

#debug, #error, #fatal, #info, #logger, #progname, #warn

Instance Method Details

#benchmark(name: nil, metric: nil, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# 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