diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-28 03:11:42 +0100 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-03-28 03:11:42 +0100 |
commit | c401ad98536b8038bf20f000b41e3f185de0ab7c (patch) | |
tree | 5e93b9dba053434f1c9350f989b44fe9c834a876 /activesupport/lib/active_support/testing/performance | |
parent | 983bd01f42a9a3f106c27b37b1074c648263e861 (diff) | |
download | rails-c401ad98536b8038bf20f000b41e3f185de0ab7c.tar.gz rails-c401ad98536b8038bf20f000b41e3f185de0ab7c.tar.bz2 rails-c401ad98536b8038bf20f000b41e3f185de0ab7c.zip |
improved options handling in performance tests
Diffstat (limited to 'activesupport/lib/active_support/testing/performance')
3 files changed, 28 insertions, 28 deletions
diff --git a/activesupport/lib/active_support/testing/performance/jruby.rb b/activesupport/lib/active_support/testing/performance/jruby.rb index 6d94dacdd6..e489c1f0dd 100644 --- a/activesupport/lib/active_support/testing/performance/jruby.rb +++ b/activesupport/lib/active_support/testing/performance/jruby.rb @@ -5,13 +5,13 @@ import java.lang.management.ManagementFactory module ActiveSupport module Testing module Performance - if ARGV.include?('--benchmark') - DEFAULTS.merge!({:metrics => [:wall_time, :user_time, :memory, :gc_runs, :gc_time]}) - else - DEFAULTS.merge!( + DEFAULTS.merge!( + if ARGV.include?('--benchmark') + {:metrics => [:wall_time, :user_time, :memory, :gc_runs, :gc_time]} + else { :metrics => [:wall_time], - :formats => [:flat, :graph] }) - end + :formats => [:flat, :graph] } + end).freeze protected def run_gc @@ -23,7 +23,7 @@ module ActiveSupport class Profiler < Performer def run @data = JRuby::Profiler.profile do - profile_options[:runs].to_i.times { run_test(@metric, :profile) } + full_profile_options[:runs].to_i.times { run_test(@metric, :profile) } end profile_printer = JRuby::Profiler::GraphProfilePrinter.new(@data) @@ -37,7 +37,7 @@ module ActiveSupport end def record - klasses = profile_options[:formats].map { |f| JRuby::Profiler.const_get("#{f.to_s.camelize}ProfilePrinter") }.compact + klasses = full_profile_options[:formats].map { |f| JRuby::Profiler.const_get("#{f.to_s.camelize}ProfilePrinter") }.compact klasses.each do |klass| fname = output_filename(klass) diff --git a/activesupport/lib/active_support/testing/performance/rubinius.rb b/activesupport/lib/active_support/testing/performance/rubinius.rb index bdbb530b37..55b142e20c 100644 --- a/activesupport/lib/active_support/testing/performance/rubinius.rb +++ b/activesupport/lib/active_support/testing/performance/rubinius.rb @@ -3,13 +3,13 @@ require 'rubinius/agent' module ActiveSupport module Testing module Performance - if ARGV.include?('--benchmark') - DEFAULTS.merge!({:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]}) - else - DEFAULTS.merge!( + DEFAULTS.merge!( + if ARGV.include?('--benchmark') + {:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]} + else { :metrics => [:wall_time], - :formats => [:flat, :graph] }) - end + :formats => [:flat, :graph] } + end).freeze protected def run_gc @@ -23,7 +23,7 @@ module ActiveSupport @profiler = Rubinius::Profiler::Instrumenter.new @profiler.profile(false) do - profile_options[:runs].to_i.times { run_test(@metric, :profile) } + full_profile_options[:runs].to_i.times { run_test(@metric, :profile) } end @total = @profiler.info[:runtime] / 1000 / 1000 / 1000.0 # seconds @@ -34,13 +34,13 @@ module ActiveSupport end def record - if(profile_options[:formats].include?(:flat)) + if(full_profile_options[:formats].include?(:flat)) create_path_and_open_file(:flat) do |file| @profiler.show(file) end end - if(profile_options[:formats].include?(:graph)) + if(full_profile_options[:formats].include?(:graph)) create_path_and_open_file(:graph) do |file| @profiler.show(file) end diff --git a/activesupport/lib/active_support/testing/performance/ruby.rb b/activesupport/lib/active_support/testing/performance/ruby.rb index b36b201531..a8b26b85eb 100644 --- a/activesupport/lib/active_support/testing/performance/ruby.rb +++ b/activesupport/lib/active_support/testing/performance/ruby.rb @@ -8,14 +8,14 @@ end module ActiveSupport module Testing module Performance - if ARGV.include?('--benchmark') - DEFAULTS.merge!({:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]}) - else - DEFAULTS.merge!( + DEFAULTS.merge!( + if ARGV.include?('--benchmark') + ({:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]} + else { :min_percent => 0.01, :metrics => [:process_time, :memory, :objects], - :formats => [:flat, :graph_html, :call_tree] }) - end + :formats => [:flat, :graph_html, :call_tree] } + end).freeze protected def run_gc @@ -36,7 +36,7 @@ module ActiveSupport RubyProf.measure_mode = @metric.measure_mode RubyProf.start RubyProf.pause - profile_options[:runs].to_i.times { run_test(@metric, :profile) } + full_profile_options[:runs].to_i.times { run_test(@metric, :profile) } @data = RubyProf.stop @total = @data.threads.values.sum(0) { |method_infos| method_infos.max.total_time } end @@ -52,13 +52,13 @@ module ActiveSupport def record return unless @supported - klasses = profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact + klasses = full_profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact klasses.each do |klass| fname = output_filename(klass) FileUtils.mkdir_p(File.dirname(fname)) File.open(fname, 'wb') do |file| - klass.new(@data).print(file, profile_options.slice(:min_percent)) + klass.new(@data).print(file, full_profile_options.slice(:min_percent)) end end end @@ -166,9 +166,9 @@ module ActiveSupport end end -if RUBY_VERSION >= '1.9.2' +if RUBY_VERSION.between?('1.9.2', '2.0') require 'active_support/testing/performance/ruby/yarv' -elsif RUBY_VERSION >= '1.8.6' +elsif RUBY_VERSION.between?('1.8.6', '1.9') require 'active_support/testing/performance/ruby/mri' else $stderr.puts 'Update your ruby interpreter to be able to run benchmarks.' |