From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/benchmark/gc/gcbench.rb | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 jni/ruby/benchmark/gc/gcbench.rb (limited to 'jni/ruby/benchmark/gc/gcbench.rb') diff --git a/jni/ruby/benchmark/gc/gcbench.rb b/jni/ruby/benchmark/gc/gcbench.rb new file mode 100644 index 0000000..09a4044 --- /dev/null +++ b/jni/ruby/benchmark/gc/gcbench.rb @@ -0,0 +1,56 @@ +require 'benchmark' +require 'pp' +require 'optparse' + +$list = true +$gcprof = true + +opt = OptionParser.new +opt.on('-q'){$list = false} +opt.on('-d'){$gcprof = false} +opt.parse!(ARGV) + +script = File.join(File.dirname(__FILE__), ARGV.shift) +script += '.rb' unless FileTest.exist?(script) +raise "#{script} not found" unless FileTest.exist?(script) + +puts "Script: #{script}" + +if $gcprof + GC::Profiler.enable +end + +tms = Benchmark.measure{|x| + load script +} + +gc_time = 0 + +if $gcprof + gc_time = GC::Profiler.total_time + GC::Profiler.report if $list and RUBY_VERSION >= '2.0.0' # before 1.9.3, report() may run infinite loop + GC::Profiler.disable +end + +pp GC.stat + +puts "#{RUBY_DESCRIPTION} #{GC::OPTS.inspect}" if defined?(GC::OPTS) + +desc = "#{RUBY_VERSION}#{RUBY_PATCHLEVEL >= 0 ? "p#{RUBY_PATCHLEVEL}" : "dev"}" +name = File.basename(script, '.rb') + +puts +puts script +puts Benchmark::CAPTION +puts tms +puts "GC total time (sec): #{gc_time}" + +# show High-Water Mark on Linux +if File.exist?('/proc/self/status') && /VmHWM:\s*(\d+.+)/ =~ File.read('/proc/self/status') + puts + puts "VmHWM: #{$1.chomp}" +end + +puts +puts "Summary of #{name} on #{desc}\t#{tms.real}\t#{gc_time}\t#{GC.count}" +puts " (real time in sec, GC time in sec, GC count)" -- cgit v1.2.3