aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGonçalo Silva <goncalossilva@gmail.com>2010-06-18 22:23:11 +0100
committerwycats <wycats@gmail.com>2010-06-29 17:12:37 -0700
commit68bd46ffb99282ecb589c9ed2cd0c74d0da3396e (patch)
treee450734281aa9d478c4549edbbf2b8325188edc5 /activesupport
parent3f563f169612ec340816f0a549fe9db7ff95c238 (diff)
downloadrails-68bd46ffb99282ecb589c9ed2cd0c74d0da3396e.tar.gz
rails-68bd46ffb99282ecb589c9ed2cd0c74d0da3396e.tar.bz2
rails-68bd46ffb99282ecb589c9ed2cd0c74d0da3396e.zip
performance tests now working accurately on 1.9, using Ruby with the GCdata patch
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/testing/performance.rb54
1 files changed, 18 insertions, 36 deletions
diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb
index cd628a956d..a124c6e0ca 100644
--- a/activesupport/lib/active_support/testing/performance.rb
+++ b/activesupport/lib/active_support/testing/performance.rb
@@ -260,16 +260,14 @@ begin
end
protected
- # Ruby 1.9 + extented GC profiler patch
- if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data)
+ # Ruby 1.9 with GC::Profiler
+ if defined?(GC::Profiler)
def with_gc_stats
- GC.start
- GC.disable
GC::Profiler.enable
+ GC.start
yield
ensure
GC::Profiler.disable
- GC.enable
end
# Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker)
@@ -294,7 +292,7 @@ begin
end
def format(measurement)
- if measurement < 2
+ if measurement < 1
'%d ms' % (measurement * 1000)
else
'%.2f sec' % measurement
@@ -335,14 +333,10 @@ begin
class Memory < Base
Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
- # Ruby 1.9 + extended GC profiler patch
- if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data)
+ # Ruby 1.9 + GCdata patch
+ if GC.respond_to?(:malloc_allocated_size)
def measure
- GC.enable
- GC.start
- kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0
- GC.disable
- kb
+ GC.malloc_allocated_size / 1024.0
end
# Ruby 1.8 + ruby-prof wrapper
@@ -360,14 +354,10 @@ begin
class Objects < Base
Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
- # Ruby 1.9 + extented GC profiler patch
- if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data)
+ # Ruby 1.9 + GCdata patch
+ if GC.respond_to?(:malloc_allocations)
def measure
- GC.enable
- GC.start
- count = GC::Profiler.data.last[:HEAP_TOTAL_OBJECTS]
- GC.disable
- count
+ GC.malloc_allocations
end
# Ruby 1.8 + ruby-prof wrapper
@@ -385,14 +375,10 @@ begin
class GcRuns < Base
Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS)
- # Ruby 1.9 + extented GC profiler patch
- if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data)
+ # Ruby 1.9
+ if GC.respond_to?(:count)
def measure
- GC.enable
- GC.start
- count = GC::Profiler.data.last[:GC_RUNS]
- GC.disable
- count
+ GC.count
end
# Ruby 1.8 + ruby-prof wrapper
@@ -410,25 +396,21 @@ begin
class GcTime < Base
Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME)
- # Ruby 1.9 + extented GC profiler patch
- if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data)
+ # Ruby 1.9 with GC::Profiler
+ if GC.respond_to?(:total_time)
def measure
- GC.enable
- GC.start
- sec = GC::Profiler.data.inject(0) { |total, run| total += run[:GC_TIME] }
- GC.disable
- sec
+ GC::Profiler.total_time
end
# Ruby 1.8 + ruby-prof wrapper
elsif RubyProf.respond_to?(:measure_gc_time)
def measure
- RubyProf.measure_gc_time
+ RubyProf.measure_gc_time / 1000
end
end
def format(measurement)
- '%d ms' % (measurement / 1000)
+ '%.2f ms' % measurement
end
end
end