Skip to content

Commit

Permalink
Add profiling support with stackprof.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Jan 15, 2015
1 parent ec88ce7 commit f054a61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions benchmarks/singleton_example_groups/helper.rb
@@ -1,5 +1,6 @@
require_relative "../../bundle/bundler/setup" # configures load paths
require 'rspec/core'
require 'stackprof'

class << RSpec
attr_writer :world
Expand Down Expand Up @@ -49,6 +50,32 @@ def self.define_and_run_examples(desc, count, group_meta: {}, example_meta: {})
@@runner.run_specs(groups)
end

def self.profile(count, meta = { example_meta: { apply_it: true } })
[:new, :old].map do |prefix|
prepare_implementation(prefix)

results = StackProf.run(mode: :cpu) do
define_and_run_examples("No match/#{prefix}", count, meta)
end

format_profile_results(results, prefix)
end
end

def self.format_profile_results(results, prefix)
File.open("tmp/#{prefix}_stack_prof_results.txt", "w") do |f|
StackProf::Report.new(results).print_text(false, nil, f)
end
system "open tmp/#{prefix}_stack_prof_results.txt"

File.open("tmp/#{prefix}_stack_prof_results.graphviz", "w") do |f|
StackProf::Report.new(results).print_graphviz(nil, f)
end

system "dot tmp/#{prefix}_stack_prof_results.graphviz -Tpdf > tmp/#{prefix}_stack_prof_results.pdf"
system "open tmp/#{prefix}_stack_prof_results.pdf"
end

def self.run_benchmarks
Benchmark.ips do |x|
implementations = { :old => "without", :new => "with" }
Expand Down
Expand Up @@ -6,6 +6,7 @@
end

BenchmarkHelpers.run_benchmarks
# BenchmarkHelpers.profile(1000)

__END__

Expand Down

0 comments on commit f054a61

Please sign in to comment.