aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/performance.rb
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2011-03-25 02:28:38 +0000
committerGonçalo Silva <goncalossilva@gmail.com>2011-03-25 02:28:38 +0000
commite57d264f3795537cc3a5be61d766f956f882a5bd (patch)
treeba678aef1e5f1512c7a7571c597ac0414e75d3ed /activesupport/lib/active_support/testing/performance.rb
parentc50df6351cf0d8ff50e62995b1124fd8183eafc3 (diff)
downloadrails-e57d264f3795537cc3a5be61d766f956f882a5bd.tar.gz
rails-e57d264f3795537cc3a5be61d766f956f882a5bd.tar.bz2
rails-e57d264f3795537cc3a5be61d766f956f882a5bd.zip
extracted more generic methods, added a note for methods that need to be overridden by each implementation
Diffstat (limited to 'activesupport/lib/active_support/testing/performance.rb')
-rw-r--r--activesupport/lib/active_support/testing/performance.rb99
1 files changed, 80 insertions, 19 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb
index 18e9898fe5..db7611c4fa 100644
--- a/activesupport/lib/active_support/testing/performance.rb
+++ b/activesupport/lib/active_support/testing/performance.rb
@@ -3,17 +3,6 @@ require 'rails/version'
require 'active_support/core_ext/class/delegating_attributes'
require 'active_support/core_ext/string/inflections'
-if !defined?(RUBY_ENGINE) or RUBY_ENGINE == "ruby" # MRI 1.8 or 1.9
- begin
- require 'ruby-prof'
- rescue LoadError
- $stderr.puts "Specify ruby-prof as application's dependency in Gemfile to run benchmarks."
- exit
- end
-
- require 'active_support/testing/performance/mri'
-end
-
module ActiveSupport
module Testing
module Performance
@@ -80,6 +69,19 @@ module ActiveSupport
end
protected
+ # overridden by each implementation
+ def run_gc; end
+
+ def run_warmup
+ run_gc
+
+ time = Metrics::Time.new
+ run_test(time, :benchmark)
+ puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]
+
+ run_gc
+ end
+
def run_profile(metric)
klass = profile_options[:benchmark] ? Benchmarker : Profiler
performer = klass.new(self, metric)
@@ -106,6 +108,13 @@ module ActiveSupport
"#{profile_options[:output]}/#{full_test_name}_#{@metric.name}"
end
end
+
+ # overridden by each implementation
+ class Profiler < Performer
+ def run; end
+ def report; end
+ def record; end
+ end
class Benchmarker < Performer
def run
@@ -180,14 +189,6 @@ module ActiveSupport
@name ||= self.class.name.demodulize.underscore
end
- def measure_mode
- self.class::Mode
- end
-
- def measure
- 0
- end
-
def benchmark
with_gc_stats do
before = measure
@@ -195,6 +196,13 @@ module ActiveSupport
@total += (measure - before)
end
end
+
+ # overridden by each implementation
+ def profile; end
+
+ protected
+ # overridden by each implementation
+ def with_gc_stats; end
end
class Time < Base
@@ -210,7 +218,60 @@ module ActiveSupport
end
end
end
+
+ class ProcessTime < Time
+ # overridden by each implementation
+ def measure; end
+ end
+
+ class WallTime < Time
+ # overridden by each implementation
+ def measure; end
+ end
+
+ class CpuTime < Time
+ # overridden by each implementation
+ def measure; end
+ end
+
+ class Memory < Base
+ # overridden by each implementation
+ def measure; end
+
+ def format(measurement)
+ '%.2f KB' % measurement
+ end
+ end
+
+ class Objects < Base
+ # overridden by each implementation
+ def measure; end
+
+ def format(measurement)
+ measurement.to_i.to_s
+ end
+ end
+
+ class GcRuns < Base
+ # overridden by each implementation
+ def measure; end
+
+ def format(measurement)
+ measurement.to_i.to_s
+ end
+ end
+
+ class GcTime < Base
+ # overridden by each implementation
+ def measure; end
+
+ def format(measurement)
+ '%.2f ms' % measurement
+ end
+ end
end
end
end
end
+
+require 'active_support/testing/performance/mri'