benchmark_driver 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c1f7fc0a8d066c0e6fec248737f0a6a0b62cd84b15ed40121f56817a9c6322a
4
- data.tar.gz: 95c7c9a3c4a847ac77592c4cd3dbb0a3f2068e83de442bd8184e999dda9979a9
3
+ metadata.gz: 064e5f572aa0e93b89cf6fd8fc0b0b60b853b96e8123879c2f8d4d15ee49d988
4
+ data.tar.gz: 1adf2bc7584828029a8bba49ce275750581838758318e498e6650e3e118880ac
5
5
  SHA512:
6
- metadata.gz: c0b0e1be74c8e7a8a7b849828daffd6e586a84c3d2a188c1a84882a40ec83ca7717fc66c62d3d723d53b184e582b01cdc14ca74384c3cdfb93e2b80693593706
7
- data.tar.gz: b4343234565046d92eb320eb3b5c9ffb7a73560ea9906cd7d541e7f9d065080fecc73f8d6542555abfe95a57e7438e797109acd5412ae6654b0c92631c3a2034
6
+ metadata.gz: d67e0b7d012111ad3c5db355072d0fb4eed1788699049a700568f4c5e9218bc73487041fb7a4ca825527a6a3859ca1e4117e7bf4a04d2ef484998f7aa57ebf2b
7
+ data.tar.gz: 9d59155a1f95066cf629ca9a55e91334cd0cf54214ca88f2267501469f75cd18b30b8e3bf56e9ac58b2b68b288d7f0ff4b4bc4f643a6a7cac1ebfe2b1004cd8e
@@ -1,3 +1,8 @@
1
+ # v0.7.1
2
+
3
+ - Add `x.rbenv` to Ruby interface
4
+ - Add `x.bundler` to Ruby interface
5
+
1
6
  # v0.7.0
2
7
 
3
8
  - Change Ruby interface for specifying prelude and script
data/README.md CHANGED
@@ -4,22 +4,20 @@ Fully-featured accurate benchmark driver for Ruby
4
4
 
5
5
  ## Project Status
6
6
 
7
- **Under Construction**
7
+ Beta. Features are almost implemented but interface may change in the future.
8
8
 
9
9
  ## Features
10
- NOTE: Pending ones are ~slashed~.
11
-
12
10
  ### Accurate Measurement
13
11
 
14
12
  - Low overhead benchmark by running generated script instead of calling Proc
15
13
  - Running multiple times to minimize measurement errors
16
- - Profiling memory, high-precision real time, ~user time and system time~
14
+ - Profiling memory, high-precision real time
17
15
 
18
16
  ### Pluggable & Fully Featured
19
17
 
20
- - Flexible and real-time output format in ips, execution time, ~markdown table~, etc.
18
+ - Flexible and real-time output format in ips, execution time, markdown table, etc.
21
19
  - Runner and output are all pluggable
22
- - ~Integrated benchmark support using external libraries~
20
+ - Bundler integration for benchmark that requires gems
23
21
 
24
22
  ### Flexible Interface
25
23
 
@@ -151,19 +149,6 @@ Comparison:
151
149
  str-interp (2.4.2): 4305563.1 i/s - 1.40x slower
152
150
  ```
153
151
 
154
- ## TODO
155
- ### Runner
156
- - [x] Call
157
- - [x] Exec
158
- - [ ] Eval
159
-
160
- ### Output
161
- - [x] IPS
162
- - [x] Time
163
- - [ ] CPU/System/Real Time
164
- - [ ] Memory
165
- - [ ] Markdown Table
166
-
167
152
  ## Contributing
168
153
 
169
154
  Bug reports and pull requests are welcome on GitHub at https://github.com/k0kubun/benchmark_driver.
@@ -2,7 +2,6 @@
2
2
  $:.unshift File.expand_path('../lib', __dir__)
3
3
 
4
4
  require 'benchmark/driver'
5
- require 'benchmark/driver/bundle_installer'
6
5
  require 'benchmark/driver/yaml_parser'
7
6
  require 'optparse'
8
7
  require 'yaml'
@@ -17,18 +16,14 @@ parser = OptionParser.new do |o|
17
16
  abort '-e, --executable must take argument but not given' if e.nil?
18
17
  options[:execs] ||= []
19
18
  e.split(';').each do |name_path|
20
- name, path = name_path.split('::', 2)
21
- options[:execs] << Benchmark::Driver::Configuration::Executable.new(name, path ? path.split(',') : [name])
19
+ options[:execs] << Benchmark::Driver::Configuration::Executable.parse(name_path)
22
20
  end
23
21
  end
24
22
  o.on('--rbenv [VERSIONS]', 'Ruby executables in rbenv (x.x.x,arg1,...;y.y.y,arg2,...;...)') do |r|
25
23
  abort '--rbenv must take argument but not given' if r.nil?
26
24
  options[:execs] ||= []
27
25
  r.split(';').each do |spec|
28
- version, *args = spec.split(',')
29
- path = `RBENV_VERSION='#{version}' rbenv which ruby`.rstrip
30
- abort "Failed to execute 'rbenv which ruby'" unless $?.success?
31
- options[:execs] << Benchmark::Driver::Configuration::Executable.new(version, [path, *args])
26
+ options[:execs] << Benchmark::Driver::Configuration::Executable.parse_rbenv(spec)
32
27
  end
33
28
  end
34
29
  o.on('-o', '--output [TYPE]', 'Specify output type (ips, time, memory, markdown)') do |t|
@@ -82,21 +77,13 @@ end
82
77
  # Proceed parsed options
83
78
  #
84
79
  config = Benchmark::Driver::Configuration.new(jobs)
85
- config.runner_options = Benchmark::Driver::Configuration::RunnerOptions.new(:exec)
80
+ config.runner_options = Benchmark::Driver::Configuration::RunnerOptions.new
86
81
  config.output_options = Benchmark::Driver::Configuration::OutputOptions.new(:ips)
87
82
 
88
- if options.key?(:execs)
89
- # Proceed execs first for --bundler
90
- config.runner_options.executables = options.delete(:execs)
91
- end
92
-
93
83
  options.each do |key, value|
94
84
  case key
95
85
  when :bundler
96
- config.runner_options.executables.each do |executable|
97
- Benchmark::Driver::BundleInstaller.bundle_install_for(executable)
98
- executable.command << '-rbundler/setup'
99
- end
86
+ config.runner_options.bundler = value
100
87
  when :compare
101
88
  config.output_options.compare = value
102
89
  when :dir
@@ -104,6 +91,8 @@ options.each do |key, value|
104
91
  config.jobs.each do |job|
105
92
  job.prelude = "__dir__ = #{dir.dump}.freeze; #{job.prelude}"
106
93
  end
94
+ when :execs
95
+ config.runner_options.executables = options.delete(:execs)
107
96
  when :filter
108
97
  filter = Regexp.compile(value)
109
98
  config.jobs.select! do |job|
@@ -19,6 +19,13 @@ module Benchmark
19
19
  config.runner_options.type = runner_type_for(config)
20
20
  end
21
21
 
22
+ if config.runner_options.bundler
23
+ config.runner_options.executables.each do |executable|
24
+ Benchmark::Driver::BundleInstaller.bundle_install_for(executable)
25
+ executable.command << '-rbundler/setup'
26
+ end
27
+ end
28
+
22
29
  runner_class = Runner.find(config.runner_options.type)
23
30
  output_class = Output.find(config.output_options.type)
24
31
 
@@ -88,6 +95,7 @@ end
88
95
 
89
96
  require 'benchmark/output'
90
97
  require 'benchmark/runner'
98
+ require 'benchmark/driver/bundle_installer'
91
99
  require 'benchmark/driver/error'
92
100
  require 'benchmark/driver/ruby_dsl_parser'
93
101
  require 'benchmark/driver/version'
@@ -6,7 +6,7 @@ class Benchmark::Driver::Configuration < Struct.new(:jobs, :runner_options, :out
6
6
  # @param [String,Proc] sctipt
7
7
  # @param [String,nil] prelude
8
8
  # @param [Integer,nil] loop_count - If this is nil, loop count is automatically estimated by warmup.
9
- class Job < Struct.new(:name, :script, :prelude, :loop_count)
9
+ Job = Struct.new(:name, :script, :prelude, :loop_count) do
10
10
  # @param [Integer,nil] guessed_count - Set by runner only when loop_count is nil. This is not configuration.
11
11
  attr_accessor :guessed_count
12
12
 
@@ -16,20 +16,32 @@ class Benchmark::Driver::Configuration < Struct.new(:jobs, :runner_options, :out
16
16
  end
17
17
 
18
18
  def loop_count
19
- super || guessed_count
19
+ self[:loop_count] || guessed_count
20
20
  end
21
21
  end
22
22
 
23
23
  # @param [String] name
24
24
  # @param [Array<String>] command - ["ruby", "-w", ...]. First element should be path to ruby command
25
- Executable = Struct.new(:name, :command)
25
+ Executable = Struct.new(:name, :command) do
26
+ def self.parse(name_path)
27
+ name, path = name_path.split('::', 2)
28
+ Benchmark::Driver::Configuration::Executable.new(name, path ? path.split(',') : [name])
29
+ end
30
+
31
+ def self.parse_rbenv(spec)
32
+ version, *args = spec.split(',')
33
+ path = `RBENV_VERSION='#{version}' rbenv which ruby`.rstrip
34
+ abort "Failed to execute 'rbenv which ruby'" unless $?.success?
35
+ Benchmark::Driver::Configuration::Executable.new(version, [path, *args])
36
+ end
37
+ end
26
38
 
27
39
  DEFAULT_EXECUTABLES = [Executable.new(RUBY_VERSION, [RbConfig.ruby])]
28
40
 
29
41
  # @param [Symbol] type - Type of runner
30
42
  # @param [Array<Benchmark::Driver::Configuration::Executable>] executables
31
43
  # @param [Integer,nil] repeat_count - Times to repeat benchmarks. When this is not nil, benchmark_driver will use the best result.
32
- class RunnerOptions < Struct.new(:type, :executables, :repeat_count)
44
+ RunnerOptions = Struct.new(:type, :executables, :repeat_count, :bundler) do
33
45
  def initialize(*)
34
46
  super
35
47
  self.executables ||= DEFAULT_EXECUTABLES
@@ -6,8 +6,11 @@ class Benchmark::Driver::RubyDslParser
6
6
  def initialize(runner: nil, output: :ips)
7
7
  @prelude = nil
8
8
  @jobs = []
9
- @runner_options = Benchmark::Driver::Configuration::RunnerOptions.new(runner)
10
- @output_options = Benchmark::Driver::Configuration::OutputOptions.new(output)
9
+ @runner = runner
10
+ @execs = []
11
+ @bundler = false
12
+ @output = :ips
13
+ @compare = false
11
14
  end
12
15
 
13
16
  # API to fetch configuration parsed from DSL
@@ -17,8 +20,8 @@ class Benchmark::Driver::RubyDslParser
17
20
  job.prelude = @prelude
18
21
  end
19
22
  Benchmark::Driver::Configuration.new(@jobs).tap do |c|
20
- c.runner_options = @runner_options
21
- c.output_options = @output_options
23
+ c.runner_options = Benchmark::Driver::Configuration::RunnerOptions.new(@runner, @execs, nil, @bundler)
24
+ c.output_options = Benchmark::Driver::Configuration::OutputOptions.new(@output, @compare)
22
25
  end
23
26
  end
24
27
 
@@ -34,6 +37,17 @@ class Benchmark::Driver::RubyDslParser
34
37
  @prelude = prelude_script
35
38
  end
36
39
 
40
+ # @param [Array<String>] specs
41
+ def rbenv(*specs)
42
+ specs.each do |spec|
43
+ @execs << Benchmark::Driver::Configuration::Executable.parse_rbenv(spec)
44
+ end
45
+ end
46
+
47
+ def bundler
48
+ @bundler = true
49
+ end
50
+
37
51
  # @param [String,nil] name - Name shown on result output. This must be provided if block is given.
38
52
  # @param [String,nil] script - Benchmarked script in String. Only either of script or block must be provided.
39
53
  # @param [Proc,nil] block - Benchmarked Proc object.
@@ -52,6 +66,6 @@ class Benchmark::Driver::RubyDslParser
52
66
  end
53
67
 
54
68
  def compare!
55
- @output_options.compare = true
69
+ @compare = true
56
70
  end
57
71
  end
@@ -1,5 +1,5 @@
1
1
  module Benchmark
2
2
  module Driver
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun