summaryrefslogtreecommitdiff
path: root/benchmark/driver.rb
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/driver.rb')
-rwxr-xr-xbenchmark/driver.rb68
1 files changed, 12 insertions, 56 deletions
diff --git a/benchmark/driver.rb b/benchmark/driver.rb
index 4185e20232..b673a84ca0 100755
--- a/benchmark/driver.rb
+++ b/benchmark/driver.rb
@@ -11,7 +11,6 @@ rescue LoadError
end
require 'shellwords'
-require 'tempfile'
class BenchmarkDriver
# Run benchmark-driver prepared by `make update-benchmark-driver`
@@ -23,69 +22,27 @@ class BenchmarkDriver
end
end
- def initialize(dir, opt = {})
- @dir = dir
- @pattern = opt[:pattern] || nil
- @exclude = opt[:exclude] || nil
- end
-
- def with_yamls(&block)
- ios = files.map do |file|
- Tempfile.open.tap do |io|
- if file.end_with?('.yml')
- io.write(File.read(file))
- else
- io.write(build_yaml(file))
- end
- io.close
- end
- end
- block.call(ios.map(&:path))
- ensure
- ios.each(&:close)
- end
-
- private
-
- def build_yaml(file)
- magic_comment = '# prelude' # bm_so_nsieve_bits hangs without magic comment
- name = File.basename(file).sub(/\Abm_/, '').sub(/\.rb\z/, '')
- script = File.read(file).sub(/^__END__\n(.+\n)*/m, '').sub(/\A(^#[^\n]+\n)+/m) do |comment|
- magic_comment = comment
- ''
- end
-
- <<-YAML
-prelude: |
-#{magic_comment.gsub(/^/, ' ')}
-benchmark:
- #{name}: |
-#{script.gsub(/^/, ' ')}
-loop_count: 1
- YAML
+ def initialize(opt = {})
+ @dir = opt[:dir]
+ @pattern = opt[:pattern]
+ @exclude = opt[:exclude]
end
def files
- flag = {}
- legacy_files = Dir.glob(File.join(@dir, 'bm*.rb'))
- yaml_files = Dir.glob(File.join(@dir, '*.yml'))
- files = (legacy_files + yaml_files).map{|file|
+ Dir.glob(File.join(@dir, '*.yml')).map{|file|
next if @pattern && /#{@pattern}/ !~ File.basename(file)
next if @exclude && /#{@exclude}/ =~ File.basename(file)
file
- }.compact
-
- files.sort!
- files
+ }.compact.sort
end
end
if __FILE__ == $0
opt = {
- :execs => [],
- :dir => File.dirname(__FILE__),
- :repeat => 1,
- :verbose => 1,
+ execs: [],
+ dir: File.dirname(__FILE__),
+ repeat: 1,
+ verbose: 1,
}
parser = OptionParser.new{|o|
@@ -123,7 +80,6 @@ if __FILE__ == $0
parser.parse!(ARGV)
execs = opt[:execs].map { |exec| ['--executables', exec.shellsplit.join(',')] }.flatten
- BenchmarkDriver.new(opt[:dir], opt).with_yamls do |yamls|
- BenchmarkDriver.run(*yamls, *execs, "--verbose=#{opt[:verbose]}", "--repeat-count=#{opt[:repeat]}")
- end
+ yamls = BenchmarkDriver.new(opt).files
+ BenchmarkDriver.run(*yamls, *execs, "--verbose=#{opt[:verbose]}", "--repeat-count=#{opt[:repeat]}")
end