Sha256: cd0352d704e7e66d61376932c27ab1a4198987071f6a8111bb3a60f210492cc5

Contents?: true

Size: 823 Bytes

Versions: 2

Compression:

Stored size: 823 Bytes

Contents

module Misc
  def self.benchmark(repeats = 1, message = nil)
    require 'benchmark'
    res = nil
    begin
      measure = Benchmark.measure do
        repeats.times do
          res = yield
        end
      end
      if message
        puts "#{message }: #{ repeats } repeats"
      else
        puts "Benchmark for #{ repeats } repeats"
      end
      puts measure
    rescue Exception
      puts "Benchmark aborted"
      raise $!
    end
    res
  end

  def self.profile(options = {})
    require 'ruby-prof'
    profiler = RubyProf::Profile.new
    profiler.start
    begin
      res = yield
    rescue Exception
      puts "Profiling aborted"
      raise $!
    ensure
      result = profiler.stop
      printer = RubyProf::FlatPrinter.new(result)
      printer.print(STDOUT, options)
    end

    res
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scout-gear-7.1.0 lib/scout/misc/monitor.rb
scout-gear-6.0.0 lib/scout/misc/monitor.rb