aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/testing/performance.rb99
-rw-r--r--activesupport/lib/active_support/testing/performance/mri.rb36
2 files changed, 87 insertions, 48 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'
diff --git a/activesupport/lib/active_support/testing/performance/mri.rb b/activesupport/lib/active_support/testing/performance/mri.rb
index cfa48890dc..914e546090 100644
--- a/activesupport/lib/active_support/testing/performance/mri.rb
+++ b/activesupport/lib/active_support/testing/performance/mri.rb
@@ -8,17 +8,12 @@ end
module ActiveSupport
module Testing
module Performance
+
protected
- def run_warmup
- GC.start
-
- time = Metrics::Time.new
- run_test(time, :benchmark)
- puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]
-
+ def run_gc
GC.start
end
-
+
class Performer; end
class Profiler < Performer
@@ -81,6 +76,10 @@ module ActiveSupport
module Metrics
class Base
+ def measure_mode
+ self.class::Mode
+ end
+
def profile
RubyProf.resume
yield
@@ -107,11 +106,6 @@ module ActiveSupport
ensure
GC.disable_stats
end
-
- else
- def with_gc_stats
- yield
- end
end
end
@@ -162,10 +156,6 @@ module ActiveSupport
RubyProf.measure_memory / 1024.0
end
end
-
- def format(measurement)
- '%.2f KB' % measurement
- end
end
class Objects < Base
@@ -183,10 +173,6 @@ module ActiveSupport
RubyProf.measure_allocations
end
end
-
- def format(measurement)
- measurement.to_i.to_s
- end
end
class GcRuns < Base
@@ -204,10 +190,6 @@ module ActiveSupport
RubyProf.measure_gc_runs
end
end
-
- def format(measurement)
- measurement.to_i.to_s
- end
end
class GcTime < Base
@@ -225,10 +207,6 @@ module ActiveSupport
RubyProf.measure_gc_time / 1000
end
end
-
- def format(measurement)
- '%.2f ms' % measurement
- end
end
end
end