class Object

Constants

EXEC_TIMES_DESC
TEST_TIMES_DESC

Public Instance Methods

is_int?(candidate) click to toggle source
# File lib/pry-measure/measure_command.rb, line 50
def is_int?(candidate)
  !!(candidate =~ /^[-+]?[0-9]+$/)
end
options(opt) click to toggle source
# File lib/pry-measure/measure_command.rb, line 28
def options(opt)
  opt.on :c, :count, EXEC_TIMES_DESC, optional: true, argument: true
  opt.on :t, :times, TEST_TIMES_DESC, optional: true, argument: true
end
process() click to toggle source
# File lib/pry-measure/measure_command.rb, line 41
def process
  @test_times = validate(opts[:count]) if opts[:count]
  @exec_times = validate(opts[:times]) if opts[:times]

  code = args.join(' ')

  PryMeasure::Marker.measure @exec_times, @test_times, code
end
pry_measure(test_times = 10, exec_times = 1) { || ... } click to toggle source
# File lib/pry-measure/helper_methods.rb, line 12
def pry_measure(test_times = 10, exec_times = 1, &b)
  Benchmark.bm do |x|
    test_times.times do
      x.report do
        exec_times.times do
          yield
        end
      end
    end
  end
end
setup() click to toggle source
# File lib/pry-measure/measure_command.rb, line 23
def setup
  @test_times = 10
  @exec_times = 1
end
time_method(object, method, *args) click to toggle source

Credit for ‘time_method`: www.skorks.com/2010/03/timing-ruby-code-it-is-easy-with-benchmark/

# File lib/pry-measure/helper_methods.rb, line 5
def time_method(object, method, *args)
  beginning_time = Time.now
  object.send(method, *args)
  end_time = Time.now
  puts "Time elapsed #{(end_time - beginning_time)*1000} milliseconds"
end
validate(option) click to toggle source
# File lib/pry-measure/measure_command.rb, line 33
def validate(option)
  unless is_int?(option)
    raise Pry::CommandError, "#{option} isn't an integer"
  end

  option.to_i
end