aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/performance.rb
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2010-06-12 11:34:53 +0100
committerwycats <wycats@gmail.com>2010-06-17 19:18:52 -0700
commit901452d06ac39f9870bba27a8bc4c6e4f100f90f (patch)
treea8a2944565ab21653f7513f8612271a16a64dabb /activesupport/lib/active_support/testing/performance.rb
parent381a30fbba6ccca0bf2e7e2bc007ea5e6848af62 (diff)
downloadrails-901452d06ac39f9870bba27a8bc4c6e4f100f90f.tar.gz
rails-901452d06ac39f9870bba27a8bc4c6e4f100f90f.tar.bz2
rails-901452d06ac39f9870bba27a8bc4c6e4f100f90f.zip
the official profiler (present in 1.9) should have the highest priority
Diffstat (limited to 'activesupport/lib/active_support/testing/performance.rb')
-rw-r--r--activesupport/lib/active_support/testing/performance.rb62
1 files changed, 31 insertions, 31 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb
index 6e51dbb735..2617763175 100644
--- a/activesupport/lib/active_support/testing/performance.rb
+++ b/activesupport/lib/active_support/testing/performance.rb
@@ -260,14 +260,7 @@ begin
end
protected
- if GC.respond_to?(:enable_stats)
- def with_gc_stats
- GC.enable_stats
- yield
- ensure
- GC.disable_stats
- end
- elsif defined?(GC::Profiler)
+ if defined?(GC::Profiler)
def with_gc_stats
GC.start
GC.disable
@@ -277,6 +270,13 @@ begin
GC::Profiler.disable
GC.enable
end
+ elsif GC.respond_to?(:enable_stats)
+ def with_gc_stats
+ GC.enable_stats
+ yield
+ ensure
+ GC.disable_stats
+ end
else
def with_gc_stats
yield
@@ -331,8 +331,18 @@ begin
class Memory < Base
Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
+ # Ruby 1.9 + GC profiler patch
+ if defined?(GC::Profiler)
+ def measure
+ GC.enable
+ GC.start
+ kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0
+ GC.disable
+ kb
+ end
+
# ruby-prof wrapper
- if RubyProf.respond_to?(:measure_memory)
+ elsif RubyProf.respond_to?(:measure_memory)
def measure
RubyProf.measure_memory / 1024.0
end
@@ -360,16 +370,6 @@ begin
def measure
GC.malloc_allocated_size / 1024.0
end
-
- # Ruby 1.9 + GC profiler patch
- elsif defined?(GC::Profiler)
- def measure
- GC.enable
- GC.start
- kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0
- GC.disable
- kb
- end
end
def format(measurement)
@@ -380,19 +380,8 @@ begin
class Objects < Base
Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
- if RubyProf.respond_to?(:measure_allocations)
- def measure
- RubyProf.measure_allocations
- end
-
- # Ruby 1.8 + railsbench patch
- elsif ObjectSpace.respond_to?(:allocated_objects)
- def measure
- ObjectSpace.allocated_objects
- end
-
# Ruby 1.9 + GC profiler patch
- elsif defined?(GC::Profiler)
+ if defined?(GC::Profiler)
def measure
GC.enable
GC.start
@@ -401,6 +390,17 @@ begin
GC.disable
count
end
+
+ elsif RubyProf.respond_to?(:measure_allocations)
+ def measure
+ RubyProf.measure_allocations
+ end
+
+ # Ruby 1.8 + railsbench patch
+ elsif ObjectSpace.respond_to?(:allocated_objects)
+ def measure
+ ObjectSpace.allocated_objects
+ end
end
def format(measurement)