提交 68bd46ff 编写于 作者: G Gonçalo Silva 提交者: wycats

performance tests now working accurately on 1.9, using Ruby with the GCdata patch

上级 3f563f16
...@@ -260,16 +260,14 @@ def profile ...@@ -260,16 +260,14 @@ def profile
end end
protected protected
# Ruby 1.9 + extented GC profiler patch # Ruby 1.9 with GC::Profiler
if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) if defined?(GC::Profiler)
def with_gc_stats def with_gc_stats
GC.start
GC.disable
GC::Profiler.enable GC::Profiler.enable
GC.start
yield yield
ensure ensure
GC::Profiler.disable GC::Profiler.disable
GC.enable
end end
# Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker) # Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker)
...@@ -294,7 +292,7 @@ def measure ...@@ -294,7 +292,7 @@ def measure
end end
def format(measurement) def format(measurement)
if measurement < 2 if measurement < 1
'%d ms' % (measurement * 1000) '%d ms' % (measurement * 1000)
else else
'%.2f sec' % measurement '%.2f sec' % measurement
...@@ -335,14 +333,10 @@ def measure ...@@ -335,14 +333,10 @@ def measure
class Memory < Base class Memory < Base
Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY) Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
# Ruby 1.9 + extended GC profiler patch # Ruby 1.9 + GCdata patch
if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) if GC.respond_to?(:malloc_allocated_size)
def measure def measure
GC.enable GC.malloc_allocated_size / 1024.0
GC.start
kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0
GC.disable
kb
end end
# Ruby 1.8 + ruby-prof wrapper # Ruby 1.8 + ruby-prof wrapper
...@@ -360,14 +354,10 @@ def format(measurement) ...@@ -360,14 +354,10 @@ def format(measurement)
class Objects < Base class Objects < Base
Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS) Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
# Ruby 1.9 + extented GC profiler patch # Ruby 1.9 + GCdata patch
if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) if GC.respond_to?(:malloc_allocations)
def measure def measure
GC.enable GC.malloc_allocations
GC.start
count = GC::Profiler.data.last[:HEAP_TOTAL_OBJECTS]
GC.disable
count
end end
# Ruby 1.8 + ruby-prof wrapper # Ruby 1.8 + ruby-prof wrapper
...@@ -385,14 +375,10 @@ def format(measurement) ...@@ -385,14 +375,10 @@ def format(measurement)
class GcRuns < Base class GcRuns < Base
Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS) Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS)
# Ruby 1.9 + extented GC profiler patch # Ruby 1.9
if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) if GC.respond_to?(:count)
def measure def measure
GC.enable GC.count
GC.start
count = GC::Profiler.data.last[:GC_RUNS]
GC.disable
count
end end
# Ruby 1.8 + ruby-prof wrapper # Ruby 1.8 + ruby-prof wrapper
...@@ -410,25 +396,21 @@ def format(measurement) ...@@ -410,25 +396,21 @@ def format(measurement)
class GcTime < Base class GcTime < Base
Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME) Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME)
# Ruby 1.9 + extented GC profiler patch # Ruby 1.9 with GC::Profiler
if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) if GC.respond_to?(:total_time)
def measure def measure
GC.enable GC::Profiler.total_time
GC.start
sec = GC::Profiler.data.inject(0) { |total, run| total += run[:GC_TIME] }
GC.disable
sec
end end
# Ruby 1.8 + ruby-prof wrapper # Ruby 1.8 + ruby-prof wrapper
elsif RubyProf.respond_to?(:measure_gc_time) elsif RubyProf.respond_to?(:measure_gc_time)
def measure def measure
RubyProf.measure_gc_time RubyProf.measure_gc_time / 1000
end end
end end
def format(measurement) def format(measurement)
'%d ms' % (measurement / 1000) '%.2f ms' % measurement
end end
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册