diff options
Diffstat (limited to 'activesupport/lib/active_support/testing/performance/ruby/yarv.rb')
-rw-r--r-- | activesupport/lib/active_support/testing/performance/ruby/yarv.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/testing/performance/ruby/yarv.rb b/activesupport/lib/active_support/testing/performance/ruby/yarv.rb new file mode 100644 index 0000000000..dcbea17a22 --- /dev/null +++ b/activesupport/lib/active_support/testing/performance/ruby/yarv.rb @@ -0,0 +1,66 @@ +begin + gem 'test-unit' +rescue LoadError + $stderr.puts 'Specify test-unit as application\'s dependency in Gemfile to run benchmarks.' + exit +end + +module ActiveSupport + module Testing + module Performance + module Metrics + class Base + protected + # Ruby 1.9 with GC::Profiler + if defined?(GC::Profiler) + def with_gc_stats + GC::Profiler.enable + GC.start + yield + ensure + GC::Profiler.disable + end + end + end + + class Memory < DigitalInformationUnit + # Ruby 1.9 + GCdata patch + if GC.respond_to?(:malloc_allocated_size) + def measure + GC.malloc_allocated_size + end + end + end + + class Amount < Base; end + + class Objects < Amount + # Ruby 1.9 + GCdata patch + if GC.respond_to?(:malloc_allocations) + def measure + GC.malloc_allocations + end + end + end + + class GcRuns < Amount + # Ruby 1.9 + if GC.respond_to?(:count) + def measure + GC.count + end + end + end + + class GcTime < Time + # Ruby 1.9 with GC::Profiler + if defined?(GC::Profiler) && GC::Profiler.respond_to?(:total_time) + def measure + GC::Profiler.total_time + end + end + end + end + end + end +end |