aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/performance.rb
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2011-03-28 03:11:42 +0100
committerGonçalo Silva <goncalossilva@gmail.com>2011-03-28 03:11:42 +0100
commitc401ad98536b8038bf20f000b41e3f185de0ab7c (patch)
tree5e93b9dba053434f1c9350f989b44fe9c834a876 /activesupport/lib/active_support/testing/performance.rb
parent983bd01f42a9a3f106c27b37b1074c648263e861 (diff)
downloadrails-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.rb')
-rw-r--r--activesupport/lib/active_support/testing/performance.rb25
1 files changed, 14 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb
index 6a0fc9af35..3195750841 100644
--- a/activesupport/lib/active_support/testing/performance.rb
+++ b/activesupport/lib/active_support/testing/performance.rb
@@ -7,7 +7,7 @@ require 'action_view/helpers/number_helper'
module ActiveSupport
module Testing
module Performance
- # modified by each implementation
+ # each implementation should define metrics and freeze the defaults
DEFAULTS =
if ARGV.include?('--benchmark') # HAX for rake test
{ :benchmark => true,
@@ -21,13 +21,16 @@ module ActiveSupport
def self.included(base)
base.superclass_delegating_accessor :profile_options
- base.profile_options = DEFAULTS
+ end
+
+ def full_profile_options
+ DEFAULTS.merge(profile_options)
end
def full_test_name
"#{self.class.name}##{method_name}"
end
-
+
def run(result)
return if method_name =~ /^default_test$/
@@ -35,13 +38,13 @@ module ActiveSupport
@_result = result
run_warmup
- if profile_options && metrics = profile_options[:metrics]
+ if full_profile_options && metrics = full_profile_options[:metrics]
metrics.each do |metric_name|
if klass = Metrics[metric_name.to_sym]
run_profile(klass.new)
result.add_run
else
- puts '%20s: unsupported' % metric_name
+ puts '%20s: unsupported' % @metric.name
end
end
end
@@ -83,7 +86,7 @@ module ActiveSupport
end
def run_profile(metric)
- klass = profile_options[:benchmark] ? Benchmarker : Profiler
+ klass = full_profile_options[:benchmark] ? Benchmarker : Profiler
performer = klass.new(self, metric)
performer.run
@@ -92,20 +95,20 @@ module ActiveSupport
end
class Performer
- delegate :run_test, :profile_options, :full_test_name, :to => :@harness
+ delegate :run_test, :full_profile_options, :full_test_name, :to => :@harness
def initialize(harness, metric)
@harness, @metric = harness, metric
end
def report
- rate = @total / profile_options[:runs]
+ rate = @total / full_profile_options[:runs]
'%20s: %s' % [@metric.name, @metric.format(rate)]
end
protected
def output_filename
- "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}"
+ "#{full_profile_options[:output]}/#{full_test_name}_#{@metric.name}"
end
end
@@ -122,12 +125,12 @@ module ActiveSupport
class Benchmarker < Performer
def run
- profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
+ full_profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
@total = @metric.total
end
def record
- avg = @metric.total / profile_options[:runs].to_i
+ avg = @metric.total / full_profile_options[:runs].to_i
now = Time.now.utc.xmlschema
with_output_file do |file|
file.puts "#{avg},#{now},#{environment}"