Permalink
Browse files

add PROFILE=1 to wrap benchmarks in ruby-prof

  • Loading branch information...
1 parent 88d9b2c commit a5c16871216007ada7aca367750d06bddecc8379 @tmm1 tmm1 committed Dec 7, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 test/profile/benchmark.rb
View
@@ -9,6 +9,11 @@
require 'benchmark'
require 'rubygems'
require 'ruby-debug' if ENV['DEBUG'] && !JRUBY
+if ENV['PROFILE']
+ require 'ruby-prof'
+ require 'fileutils'
+ FileUtils.mkdir_p 'profiles'
+end
begin; require 'memory'; rescue LoadError; end
@@ -153,7 +158,12 @@ def benchmark_clients(test_name, populate_keys = true)
10003.times { yield client }
GC.disable if !JRUBY
+ RubyProf.start if ENV['PROFILE']
@benchmark.report("#{test_name}: #{client_name}") { @loops.times { yield client } }
+ if ENV['PROFILE']
+ prof = RubyProf::MultiPrinter.new(RubyProf.stop)
+ prof.print(:path => 'profiles', :profile => "#{test_name}-#{client_name.gsub(':','-')}")
+ end
rescue Exception => e
puts "#{test_name}: #{client_name} => #{e.inspect}" if ENV["DEBUG"]
reset_clients

0 comments on commit a5c1687

Please sign in to comment.