Sha256: fb15f6229e2385ad0ca83e64bbf6bf6dbe00d9d677e9eb86cbbcba5f92c9c0ff

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'stackprof'
require 'benchmark'

$LOAD_PATH.unshift('.')
require 'lib/modis'

puts "Profiler enabled." if ENV['PROFILE']

Modis.configure do |config|
  config.namespace = 'modis_benchmark'
end

class Bench
  def self.run
    bench = new
    yield(bench)
    bench._run
  end

  def initialize
    @bms = []
    @profiles = []
  end

  def report(name, &blk)
    @bms << [name, blk]
  end

  def _run
    Benchmark.bmbm do |x|
      @bms.each do |name, blk|
        x.report(name) do
          with_profile(name, &blk)
        end
      end
    end

    after
  end

  private

  def with_profile(name)
    if ENV['PROFILE']
      mode = :wall
      out = "tmp/stackprof-#{mode}-#{name}.dump"
      @profiles << out
      StackProf.run(mode: mode, out: out, &Proc.new)
    else
      yield
    end
  end

  def after
    Modis.with_connection do |connection|
      keys = connection.keys "#{Modis.config.namespace}:*"
      connection.del(*keys) unless keys.empty?
    end

    return unless @profiles.any?

    puts "\nProfiler dumps:"
    @profiles.uniq.each { |dump| puts " * stackprof #{dump} --text" }
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
modis-4.3.2 benchmark/bench.rb
modis-4.3.1 benchmark/bench.rb
modis-4.3.0 benchmark/bench.rb
modis-4.2.0 benchmark/bench.rb
modis-4.1.0 benchmark/bench.rb
modis-4.0.1 benchmark/bench.rb
modis-4.0.0 benchmark/bench.rb
modis-3.3.0 benchmark/bench.rb
modis-3.2.0 benchmark/bench.rb
modis-3.1.0 benchmark/bench.rb
modis-3.0.0 benchmark/bench.rb
modis-2.1.0 benchmark/bench.rb
modis-2.0.0 benchmark/bench.rb