mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* benchmark/driver.rb: support memory usage benchmark.
use `--measure-target=[target]'. Now, we can use the following targets: * real (default): real time which returns process time in sec. * peak: peak memory usage (physical memory) in bytes. * size: last memory usage (physical memory) in bytes. * benchmark/memory_wrapper.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2d3a6ba66d
commit
61aa2685d3
3 changed files with 62 additions and 8 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Wed Mar 9 16:20:25 2016 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* benchmark/driver.rb: support memory usage benchmark.
|
||||||
|
use `--measure-target=[target]'.
|
||||||
|
Now, we can use the following targets:
|
||||||
|
* real (default): real time which returns process time in sec.
|
||||||
|
* peak: peak memory usage (physical memory) in bytes.
|
||||||
|
* size: last memory usage (physical memory) in bytes.
|
||||||
|
|
||||||
|
* benchmark/memory_wrapper.rb: ditto.
|
||||||
|
|
||||||
Wed Mar 9 15:04:22 2016 Koichi Sasada <ko1@atdot.net>
|
Wed Mar 9 15:04:22 2016 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* benchmark/bm_vm3_gc_old_full.rb: add GC.start benchmark.
|
* benchmark/bm_vm3_gc_old_full.rb: add GC.start benchmark.
|
||||||
|
|
|
@ -18,6 +18,7 @@ end
|
||||||
|
|
||||||
require 'benchmark'
|
require 'benchmark'
|
||||||
require 'pp'
|
require 'pp'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
class BenchmarkDriver
|
class BenchmarkDriver
|
||||||
def self.benchmark(opt)
|
def self.benchmark(opt)
|
||||||
|
@ -98,6 +99,7 @@ class BenchmarkDriver
|
||||||
@output = opt[:output] ? open(opt[:output], 'w') : nil
|
@output = opt[:output] ? open(opt[:output], 'w') : nil
|
||||||
@loop_wl1 = @loop_wl2 = nil
|
@loop_wl1 = @loop_wl2 = nil
|
||||||
@ruby_arg = opt[:ruby_arg] || nil
|
@ruby_arg = opt[:ruby_arg] || nil
|
||||||
|
@measure_target = opt[:measure_target]
|
||||||
@opt = opt
|
@opt = opt
|
||||||
|
|
||||||
# [[name, [[r-1-1, r-1-2, ...], [r-2-1, r-2-2, ...]]], ...]
|
# [[name, [[r-1-1, r-1-2, ...], [r-2-1, r-2-2, ...]]], ...]
|
||||||
|
@ -109,6 +111,7 @@ class BenchmarkDriver
|
||||||
@execs.each_with_index{|(path, label, version), i|
|
@execs.each_with_index{|(path, label, version), i|
|
||||||
message "target #{i}: " + (label == version ? "#{label}" : "#{label} (#{version})") + " at \"#{path}\""
|
message "target #{i}: " + (label == version ? "#{label}" : "#{label} (#{version})") + " at \"#{path}\""
|
||||||
}
|
}
|
||||||
|
message "measure target: #{@measure_target}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -196,7 +199,11 @@ class BenchmarkDriver
|
||||||
output "minimum results in each #{@repeat} measurements."
|
output "minimum results in each #{@repeat} measurements."
|
||||||
end
|
end
|
||||||
|
|
||||||
output "Execution time (sec)"
|
output({
|
||||||
|
real: "Execution time (sec)",
|
||||||
|
peak: "Memory usage (peak) (B)",
|
||||||
|
size: "Memory usage (last size) (B)",
|
||||||
|
}[@measure_target])
|
||||||
output if markdown
|
output if markdown
|
||||||
output ["name".ljust(name_width), @execs.map.with_index{|(_, v), i| sprintf(strformat, v, width[i])}].join("").rstrip
|
output ["name".ljust(name_width), @execs.map.with_index{|(_, v), i| sprintf(strformat, v, width[i])}].join("").rstrip
|
||||||
output ["-"*name_width, width.map{|n|":".rjust(n, "-")}].join("|") if markdown
|
output ["-"*name_width, width.map{|n|":".rjust(n, "-")}].join("|") if markdown
|
||||||
|
@ -211,7 +218,11 @@ class BenchmarkDriver
|
||||||
|
|
||||||
if @execs.size > 1
|
if @execs.size > 1
|
||||||
output
|
output
|
||||||
output "Speedup ratio: compare with the result of `#{@execs[0][1]}' (greater is better)"
|
output({
|
||||||
|
rss: "Memory consuming ratio (RSS) with the result of `#{@execs[0][1]}' (greater is worse)",
|
||||||
|
peak: "Memory consuming ratio (peak) with the result of `#{@execs[0][1]}' (greater is worse)",
|
||||||
|
size: "Memory consuming ratio (size) with the result of `#{@execs[0][1]}' (greater is worse)",
|
||||||
|
}[@measure_target])
|
||||||
output if markdown
|
output if markdown
|
||||||
output ["name".ljust(name_width), @execs[1..-1].map.with_index{|(_, v), i| sprintf(strformat, v, width[i])}].join("").rstrip
|
output ["name".ljust(name_width), @execs[1..-1].map.with_index{|(_, v), i| sprintf(strformat, v, width[i])}].join("").rstrip
|
||||||
output ["-"*name_width, width[1..-1].map{|n|":".rjust(n, "-")}].join("|") if markdown
|
output ["-"*name_width, width[1..-1].map{|n|":".rjust(n, "-")}].join("|") if markdown
|
||||||
|
@ -223,7 +234,7 @@ class BenchmarkDriver
|
||||||
if r == 0
|
if r == 0
|
||||||
rets << "Error"
|
rets << "Error"
|
||||||
else
|
else
|
||||||
rets << sprintf(numformat, first_value/r, width[rets.size+1])
|
rets << sprintf(numformat, first_value/Float(r), width[rets.size+1])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
first_value = r
|
first_value = r
|
||||||
|
@ -312,18 +323,30 @@ class BenchmarkDriver
|
||||||
end
|
end
|
||||||
|
|
||||||
def measure executable, file
|
def measure executable, file
|
||||||
|
case @measure_target
|
||||||
|
when :real
|
||||||
cmd = "#{executable} #{@ruby_arg} #{file}"
|
cmd = "#{executable} #{@ruby_arg} #{file}"
|
||||||
|
|
||||||
m = Benchmark.measure{
|
m = Benchmark.measure{
|
||||||
system(cmd, out: File::NULL)
|
system(cmd, out: File::NULL)
|
||||||
}
|
}
|
||||||
|
result = m.real
|
||||||
|
when :peak, :size
|
||||||
|
tmp = Tempfile.new("benchmark-memory-wrapper-data")
|
||||||
|
wrapper = "#{File.join(__dir__, 'memory_wrapper.rb')} #{tmp.path} #{@measure_target}"
|
||||||
|
cmd = "#{executable} #{@ruby_arg} #{wrapper} #{file}"
|
||||||
|
system(cmd, out: File::NULL)
|
||||||
|
result = tmp.read.to_i
|
||||||
|
tmp.close
|
||||||
|
else
|
||||||
|
raise "unknown measure target"
|
||||||
|
end
|
||||||
|
|
||||||
if $? != 0
|
if $? != 0
|
||||||
raise $?.inspect if $? && $?.signaled?
|
raise $?.inspect if $? && $?.signaled?
|
||||||
output "\`#{cmd}\' exited with abnormal status (#{$?})"
|
output "\`#{cmd}\' exited with abnormal status (#{$?})"
|
||||||
0
|
0
|
||||||
else
|
else
|
||||||
m.real
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -333,6 +356,7 @@ if __FILE__ == $0
|
||||||
:execs => [],
|
:execs => [],
|
||||||
:dir => File.dirname(__FILE__),
|
:dir => File.dirname(__FILE__),
|
||||||
:repeat => 1,
|
:repeat => 1,
|
||||||
|
:measure_target => :real,
|
||||||
:output => nil,
|
:output => nil,
|
||||||
:raw_output => nil,
|
:raw_output => nil,
|
||||||
:format => :tsv,
|
:format => :tsv,
|
||||||
|
@ -368,6 +392,9 @@ if __FILE__ == $0
|
||||||
o.on('--ruby-arg [ARG]', "Optional argument for ruby"){|a|
|
o.on('--ruby-arg [ARG]', "Optional argument for ruby"){|a|
|
||||||
opt[:ruby_arg] = a
|
opt[:ruby_arg] = a
|
||||||
}
|
}
|
||||||
|
o.on('--measure-target [TARGET]', 'real (execution time), peak, size (memory)'){|mt|
|
||||||
|
opt[:measure_target] = mt.to_sym
|
||||||
|
}
|
||||||
o.on('--rawdata-output [FILE]', 'output rawdata'){|r|
|
o.on('--rawdata-output [FILE]', 'output rawdata'){|r|
|
||||||
opt[:rawdata_output] = r
|
opt[:rawdata_output] = r
|
||||||
}
|
}
|
||||||
|
|
16
benchmark/memory_wrapper.rb
Normal file
16
benchmark/memory_wrapper.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
write_file, target, script_file = ARGV
|
||||||
|
|
||||||
|
load(script_file)
|
||||||
|
require_relative '../test/lib/memory_status'
|
||||||
|
open(write_file, 'wb'){|f|
|
||||||
|
ms = Memory::Status.new
|
||||||
|
case target.to_sym
|
||||||
|
when :peak
|
||||||
|
key = ms.member?(:hwm) ? :hwm : :peak
|
||||||
|
when :size
|
||||||
|
key = ms.member?(:rss) ? :rss : :size
|
||||||
|
end
|
||||||
|
|
||||||
|
f.puts ms[key]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue