1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/benchmark/gc/gcbench.rb
ko1 400a9a7bc2 * benchmark/gc/gcbench.rb: add some options to make quiet.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-05 22:13:08 +00:00

53 lines
1.1 KiB
Ruby

require 'benchmark'
require 'pp'
require 'optparse'
$list = true
$gcprof = true
opt = OptionParser.new
opt.on('-q'){$list = false}
opt.on('-d'){$gcprof = fales}
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
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)"