class MicroBench::Benchmark

Public Class Methods

new() click to toggle source
# File lib/micro_bench/benchmark.rb, line 4
def initialize
  @start_time = monotonic_clock_time
end

Public Instance Methods

duration() click to toggle source
# File lib/micro_bench/benchmark.rb, line 16
def duration
  @duration || (monotonic_clock_time - @start_time)
end
running?() click to toggle source
# File lib/micro_bench/benchmark.rb, line 20
def running?
  @duration.nil?
end
stop() click to toggle source
# File lib/micro_bench/benchmark.rb, line 8
def stop
  return false unless running?

  @duration = monotonic_clock_time - @start_time

  return true
end
to_s() click to toggle source
# File lib/micro_bench/benchmark.rb, line 24
def to_s
  duration.to_s
end

Private Instance Methods

monotonic_clock_time() click to toggle source
# File lib/micro_bench/benchmark.rb, line 30
def monotonic_clock_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end