class Reviewer::Shell::Timer

Provides a structured interface for measuring realtime main while running comamnds

Attributes

main[RW]
prep[RW]

Public Class Methods

new(prep: nil, main: nil) click to toggle source
# File lib/reviewer/shell/timer.rb, line 11
def initialize(prep: nil, main: nil)
  @prep = prep
  @main = main
end

Public Instance Methods

main_seconds() click to toggle source
# File lib/reviewer/shell/timer.rb, line 28
def main_seconds
  main.round(2)
end
prep_percent() click to toggle source
# File lib/reviewer/shell/timer.rb, line 36
def prep_percent
  return nil unless prepped?

  (prep / total.to_f * 100).round
end
prep_seconds() click to toggle source
# File lib/reviewer/shell/timer.rb, line 24
def prep_seconds
  prep.round(2)
end
prepped?() click to toggle source
# File lib/reviewer/shell/timer.rb, line 46
def prepped?
  !(prep.nil? || main.nil?)
end
record_main(&block) click to toggle source
# File lib/reviewer/shell/timer.rb, line 20
def record_main(&block)
  @main = record(&block)
end
record_prep(&block) click to toggle source
# File lib/reviewer/shell/timer.rb, line 16
def record_prep(&block)
  @prep = record(&block)
end
total() click to toggle source
# File lib/reviewer/shell/timer.rb, line 42
def total
  [prep, main].compact.sum
end
total_seconds() click to toggle source
# File lib/reviewer/shell/timer.rb, line 32
def total_seconds
  total.round(2)
end

Private Instance Methods

record(&block) click to toggle source
# File lib/reviewer/shell/timer.rb, line 52
def record(&block)
  Benchmark.realtime(&block)
end