exe/benchmark-driver in benchmark_driver-0.13.3 vs exe/benchmark-driver in benchmark_driver-0.14.0
- old
+ new
@@ -1,18 +1,19 @@
#!/usr/bin/env ruby
$:.unshift File.expand_path('../lib', __dir__)
require 'benchmark_driver'
require 'optparse'
+require 'shellwords'
require 'yaml'
# Parse command line options
config = BenchmarkDriver::Config.new.tap do |c|
executables = []
bundler = false
parser = OptionParser.new do |o|
- o.banner = "Usage: #{File.basename($0, '.*')} [options] [YAML]"
+ o.banner = "Usage: #{File.basename($0, '.*')} [options] [YAML|RUBY]"
o.on('-r', '--runner [TYPE]', 'Specify runner type: ips, time, memory, once (default: ips)') do |d|
abort '-r, --runner must take argument but not given' if d.nil?
c.runner_type = d
end
o.on('-o', '--output [TYPE]', 'Specify output type: compare, simple, markdown, record (default: compare)') do |out|
@@ -22,11 +23,11 @@
o.on('-e', '--executables [EXECS]', 'Ruby executables (e1::path1,arg1,...; e2::path2,arg2;...)') do |e|
abort '--executable must take argument but not given' if e.nil?
e.split(';').each do |name_path|
name, path = name_path.split('::', 2)
path ||= name # if `::` is not given, regard whole string as path
- command = path.split(',')
+ command = path.shellsplit
command[0] = File.expand_path(command[0])
executables << BenchmarkDriver::Config::Executable.new(name: name, command: command)
end
end
o.on('--rbenv [VERSIONS]', 'Ruby executables in rbenv (x.x.x,arg1,...;y.y.y,arg2,...;...)') do |r|
@@ -52,24 +53,20 @@
bundler = v
end
o.on('--filter [REGEXP]', 'Filter out benchmarks with given regexp') do |v|
c.filters << Regexp.compile(v)
end
- o.on('--verbose [LEVEL]', 'Show some verbose outputs: 0, 1, 2 (default: 0)') do |v|
- begin
- c.verbose = Integer(v)
- rescue ArgumentError
- abort "--verbose must take Integer, but got #{v.inspect}"
- end
- end
o.on('--run-duration [SECONDS]', 'Warmup estimates loop_count to run for this duration (default: 3)') do |v|
begin
c.run_duration = Float(v)
rescue ArgumentError
abort "--run-duration must take Float, but got #{v.inspect}"
end
end
+ o.on('-v', '--verbose', 'Verbose mode. Multiple -v options increase visilibity (max: 2)') do |v|
+ c.verbose += 1
+ end
end
c.paths = parser.parse!(ARGV)
if c.paths.empty?
abort "No YAML file is specified!\n\n#{parser.help}"
end
@@ -87,11 +84,20 @@
c.freeze
end
# Parse benchmark job definitions
jobs = config.paths.flat_map do |path|
- job = YAML.load(File.read(path))
- job = { 'type' => config.runner_type }.merge!(job)
+ job = { 'type' => config.runner_type }
+
+ # Treat *.rb as a single-execution benchmark, others are considered as YAML definition
+ if path.end_with?('.rb')
+ name = File.basename(path).sub(/\.rb\z/, '')
+ script = File.read(path)
+ prelude = script.slice!(/\A(^#[^\n]+\n)+/m) || '' # preserve magic comment
+ job.merge!('prelude' => prelude, 'benchmark' => { name => script }, 'loop_count' => 1)
+ else
+ job.merge!(YAML.load_file(path))
+ end
begin
# `working_directory` is YAML-specific special parameter, mainly for "command_stdout"
BenchmarkDriver::JobParser.parse(job, default_params: { working_directory: File.dirname(path) })
rescue ArgumentError