Sha256: 9e6c0c63529b96e7db92f19823a28ddc15ce461c2d39747f516b305f0246d794

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

Contents

require "benchmark"
require "perftools"

$:.unshift "./"
$:.unshift "./lib"

require "moped"
require "perf/helpers"

begin
  require "em-synchrony"
  $em = true
rescue LoadError
  $em = false
end

def without_gc
  GC.disable
  yield
  GC.enable
  GC.start
end

def with_eventmachine
  if $em
    EM.synchrony do
      yield
      EM.stop
    end
  else
    yield
  end
end

at_exit do
  Benchmark.cases.each do |name, block|
    profile_name = name.downcase.gsub /\W/, '_'

    Benchmark.before_callbacks.each &:call
    without_gc do
      PerfTools::CpuProfiler.start(
        "perf/results/#{profile_name}.profile",
        &block
      )
    end
    Benchmark.after_callbacks.each &:call
  end

  Dir.glob("perf/results/*.profile") do |profile|
    puts "Generating #{profile}.pdf..."
    `bundle exec pprof.rb --pdf #{profile} > #{profile}.pdf`
  end unless $!
end

with_eventmachine do
  require "perf/setup"
  require "perf/cases"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/bundler/gems/moped-cf817ca58a85/perf/profile.rb