benchmark_driver_monotonic_raw 0.14.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +16 -0
  5. data/CHANGELOG.md +357 -0
  6. data/Gemfile +8 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +386 -0
  9. data/Rakefile +9 -0
  10. data/benchmark-driver/.gitignore +12 -0
  11. data/benchmark-driver/CODE_OF_CONDUCT.md +74 -0
  12. data/benchmark-driver/Gemfile +6 -0
  13. data/benchmark-driver/LICENSE.txt +21 -0
  14. data/benchmark-driver/README.md +8 -0
  15. data/benchmark-driver/Rakefile +1 -0
  16. data/benchmark-driver/benchmark-driver.gemspec +21 -0
  17. data/benchmark-driver/bin/console +14 -0
  18. data/benchmark-driver/bin/setup +8 -0
  19. data/benchmark-driver/lib/benchmark-driver.rb +1 -0
  20. data/benchmark-driver/lib/benchmark/driver.rb +1 -0
  21. data/benchmark_driver.gemspec +28 -0
  22. data/bin/console +7 -0
  23. data/bin/setup +8 -0
  24. data/exe/benchmark-driver +118 -0
  25. data/images/optcarrot.png +0 -0
  26. data/lib/benchmark_driver.rb +14 -0
  27. data/lib/benchmark_driver/bulk_output.rb +59 -0
  28. data/lib/benchmark_driver/config.rb +59 -0
  29. data/lib/benchmark_driver/default_job.rb +29 -0
  30. data/lib/benchmark_driver/default_job_parser.rb +91 -0
  31. data/lib/benchmark_driver/job_parser.rb +55 -0
  32. data/lib/benchmark_driver/metric.rb +79 -0
  33. data/lib/benchmark_driver/output.rb +88 -0
  34. data/lib/benchmark_driver/output/compare.rb +216 -0
  35. data/lib/benchmark_driver/output/markdown.rb +107 -0
  36. data/lib/benchmark_driver/output/record.rb +61 -0
  37. data/lib/benchmark_driver/output/simple.rb +103 -0
  38. data/lib/benchmark_driver/rbenv.rb +25 -0
  39. data/lib/benchmark_driver/repeater.rb +52 -0
  40. data/lib/benchmark_driver/ruby_interface.rb +83 -0
  41. data/lib/benchmark_driver/runner.rb +103 -0
  42. data/lib/benchmark_driver/runner/command_stdout.rb +118 -0
  43. data/lib/benchmark_driver/runner/ips.rb +259 -0
  44. data/lib/benchmark_driver/runner/memory.rb +150 -0
  45. data/lib/benchmark_driver/runner/once.rb +118 -0
  46. data/lib/benchmark_driver/runner/recorded.rb +73 -0
  47. data/lib/benchmark_driver/runner/ruby_stdout.rb +146 -0
  48. data/lib/benchmark_driver/runner/time.rb +20 -0
  49. data/lib/benchmark_driver/struct.rb +98 -0
  50. data/lib/benchmark_driver/version.rb +3 -0
  51. metadata +150 -0
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.ruby_opts = %w[-w]
6
+ t.rspec_opts = %w[--profile]
7
+ end
8
+
9
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mamaveb@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in benchmark-driver.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 bmarkons
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ # benchmark-driver.gem
2
+
3
+ This is an alias to install `benchmark_driver.gem`.
4
+ It was built because its command name is actually `benchmark-driver`.
5
+
6
+ ## License
7
+
8
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "benchmark-driver"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["bmarkons"]
9
+ spec.email = ["mamaveb@gmail.com"]
10
+
11
+ spec.summary = %q{Alias gem to install benchmark_driver.gem}
12
+ spec.homepage = "https://github.com/benchmark-driver/benchmark-driver"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "benchmark_driver"
21
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "benchmark/driver"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require 'benchmark_driver'
@@ -0,0 +1 @@
1
+ require 'benchmark_driver'
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'benchmark_driver/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'benchmark_driver_monotonic_raw'
7
+ spec.version = BenchmarkDriver::VERSION
8
+ spec.authors = ['Simon Eskildsen']
9
+ spec.email = ['sirup@sirupsen.com']
10
+
11
+ spec.summary = 'benchmark_driver using monotonic raw'
12
+ spec.description = 'benchmark_drive using monotonic raw'
13
+ spec.homepage = 'https://github.com/benchmark-driver/benchmark-driver'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+ spec.required_ruby_version = '>= 2.2.0'
23
+
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rspec-retry'
28
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'benchmark_driver'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path('../lib', __dir__)
3
+
4
+ require 'benchmark_driver'
5
+ require 'optparse'
6
+ require 'shellwords'
7
+ require 'yaml'
8
+
9
+ # Parse command line options
10
+ config = BenchmarkDriver::Config.new.tap do |c|
11
+ executables = []
12
+ bundler = false
13
+ timeout = false
14
+
15
+ parser = OptionParser.new do |o|
16
+ o.version = BenchmarkDriver::VERSION
17
+ o.banner = "Usage: #{File.basename($0, '.*')} [options] RUBY|YAML..."
18
+ o.on('-r', '--runner TYPE', String, 'Specify runner type: ips, time, memory, once (default: ips)') do |d|
19
+ c.runner_type = d
20
+ end
21
+ o.on('-o', '--output TYPE', String, 'Specify output type: compare, simple, markdown, record (default: compare)') do |out|
22
+ c.output_type = out
23
+ end
24
+ o.on('-e', '--executables EXECS', String, 'Ruby executables (e1::path1 arg1; e2::path2 arg2;...)') do |e|
25
+ e.split(';').each do |name_path|
26
+ name, path = name_path.split('::', 2)
27
+ path ||= name # if `::` is not given, regard whole string as path
28
+ command = path.shellsplit
29
+ command[0] = File.expand_path(command[0])
30
+ executables << BenchmarkDriver::Config::Executable.new(name: name, command: command)
31
+ end
32
+ end
33
+ o.on('--rbenv VERSIONS', String, 'Ruby executables in rbenv (x.x.x arg1;y.y.y arg2;...)') do |r|
34
+ r.split(';').each do |version|
35
+ executables << BenchmarkDriver::Rbenv.parse_spec(version)
36
+ end
37
+ end
38
+ o.on('--repeat-count NUM', Integer, 'Try benchmark NUM times and use the fastest result or the worst memory usage') do |v|
39
+ c.repeat_count = v
40
+ end
41
+ o.on('--repeat-result TYPE', String, 'Yield "best", "average" or "worst" result with --repeat-count (default: best)') do |v|
42
+ unless BenchmarkDriver::Repeater::VALID_TYPES.include?(v)
43
+ raise ArgumentError.new("--repeat-result must be #{BenchmarkDriver::Repeater::VALID_TYPES.join(', ')} but got #{v.inspect}")
44
+ end
45
+ c.repeat_result = v
46
+ end
47
+ o.on('--bundler', 'Install and use gems specified in Gemfile') do |v|
48
+ bundler = v
49
+ end
50
+ o.on('--filter REGEXP', String, 'Filter out benchmarks with given regexp') do |v|
51
+ c.filters << Regexp.compile(v)
52
+ end
53
+ o.on('--run-duration SECONDS', Float, 'Warmup estimates loop_count to run for this duration (default: 3)') do |v|
54
+ c.run_duration = v
55
+ end
56
+ o.on('--timeout SECONDS', Float, 'Timeout ruby command execution with timeout(1)') do |v|
57
+ timeout = v
58
+ end if (os = RbConfig::CONFIG['host_os']) && os.match(/linux/) && system('which timeout > /dev/null') # depending on coreutils for now...
59
+ o.on('-v', '--verbose', 'Verbose mode. Multiple -v options increase visilibity (max: 2)') do |v|
60
+ c.verbose += 1
61
+ end
62
+ end
63
+ begin
64
+ c.paths = parser.parse!(ARGV)
65
+ rescue OptionParser::InvalidArgument => e
66
+ abort e.message
67
+ end
68
+ if c.paths.empty?
69
+ abort "No YAML file is specified!\n\n#{parser.help}"
70
+ end
71
+
72
+ # Configs that need to be set lazily
73
+ unless executables.empty?
74
+ c.executables = executables
75
+ end
76
+ c.executables.each do |exec|
77
+ if bundler
78
+ exec.command << '-rbundler/setup'
79
+ end
80
+ if timeout
81
+ exec.command = ['timeout', timeout.to_s, *exec.command]
82
+ end
83
+ end
84
+
85
+ c.freeze
86
+ end
87
+
88
+ # Parse benchmark job definitions
89
+ jobs = config.paths.flat_map do |path|
90
+ job = { 'type' => config.runner_type }
91
+
92
+ # Treat *.rb as a single-execution benchmark, others are considered as YAML definition
93
+ if path.end_with?('.rb')
94
+ name = File.basename(path).sub(/\.rb\z/, '')
95
+ script = File.read(path)
96
+ prelude = script.slice!(/\A(^#[^\n]+\n)+/m) || '' # preserve magic comment
97
+ job.merge!('prelude' => prelude, 'benchmark' => { name => script }, 'loop_count' => 1)
98
+ else
99
+ job.merge!(YAML.load_file(path))
100
+ end
101
+
102
+ begin
103
+ # `working_directory` is YAML-specific special parameter, mainly for "command_stdout"
104
+ BenchmarkDriver::JobParser.parse(job, default_params: { working_directory: File.dirname(path) })
105
+ rescue ArgumentError
106
+ $stderr.puts "benchmark-driver: Failed to parse #{path.dump}."
107
+ $stderr.puts ' YAML format may be wrong. See error below:'
108
+ $stderr.puts
109
+ raise
110
+ end
111
+ end.select do |job|
112
+ config.filters.all? do |filter|
113
+ job.name.match(filter)
114
+ end
115
+ end
116
+
117
+ # Run jobs
118
+ BenchmarkDriver::Runner.run(jobs, config: config)
Binary file
@@ -0,0 +1,14 @@
1
+ require 'benchmark_driver/bulk_output'
2
+ require 'benchmark_driver/config'
3
+ require 'benchmark_driver/job_parser'
4
+ require 'benchmark_driver/output'
5
+ require 'benchmark_driver/rbenv'
6
+ require 'benchmark_driver/repeater'
7
+ require 'benchmark_driver/ruby_interface'
8
+ require 'benchmark_driver/runner'
9
+ require 'benchmark_driver/version'
10
+
11
+ require 'benchmark'
12
+ def Benchmark.driver(**args, &block)
13
+ BenchmarkDriver::RubyInterface.run(**args, &block)
14
+ end
@@ -0,0 +1,59 @@
1
+ module BenchmarkDriver
2
+ # This is API for your casual output plugin and NOT internally used by BenchmarkDriver.
3
+ #
4
+ # By fully utilizing with_*/report APIs, you can implement streaming-output plugins.
5
+ # See also: lib/benchmark_driver/output.rb (this class's instance will be `@output`)
6
+ # But using these APIs can be difficult because the API is not stable yet and it's hard
7
+ # to deal with the complex state machine.
8
+ #
9
+ # If you don't need to output results in a streaming manner, you can create an output
10
+ # plugin class that inherits `BenchmarkDriver::BulkOutput`, which requires to override
11
+ # only `#bulk_output` that takes all inputs at once.
12
+ class BulkOutput
13
+ # @param [Array<BenchmarkDriver::Metric>] metrics
14
+ # @param [Array<BenchmarkDriver::Job>] jobs
15
+ # @param [Array<BenchmarkDriver::Context>] contexts
16
+ def initialize(metrics:, jobs:, contexts:)
17
+ @metrics = metrics
18
+ end
19
+
20
+ # The main API you need to override if you make a class inherit `BenchmarkDriver::BulkOutput`.
21
+ # @param [Hash{ BenchmarkDriver::Job => Hash{ BenchmarkDriver::Context => BenchmarkDriver::Result } }] job_context_result
22
+ # @param [Array<BenchmarkDriver::Metric>] metrics
23
+ def bulk_output(job_context_result:, metrics:)
24
+ raise NotImplementedError.new("#{self.class} must override #bulk_output")
25
+ end
26
+
27
+ def with_warmup(&block)
28
+ block.call # noop
29
+ end
30
+
31
+ def with_benchmark(&block)
32
+ @job_context_result = Hash.new do |hash, job|
33
+ hash[job] = {}
34
+ end
35
+ result = block.call
36
+ bulk_output(job_context_result: @job_context_result, metrics: @metrics)
37
+ result
38
+ end
39
+
40
+ # @param [BenchmarkDriver::Job] job
41
+ def with_job(job, &block)
42
+ @job = job
43
+ block.call
44
+ end
45
+
46
+ # @param [BenchmarkDriver::Context] context
47
+ def with_context(context, &block)
48
+ @context = context
49
+ block.call
50
+ end
51
+
52
+ # @param [BenchmarkDriver::Result] result
53
+ def report(result)
54
+ if defined?(@job_context_result)
55
+ @job_context_result[@job][@context] = result
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
1
+ require 'benchmark_driver/struct'
2
+ require 'rbconfig'
3
+
4
+ module BenchmarkDriver
5
+ # All CLI options
6
+ Config = ::BenchmarkDriver::Struct.new(
7
+ :runner_type, # @param [String]
8
+ :output_type, # @param [String]
9
+ :paths, # @param [Array<String>]
10
+ :executables, # @param [Array<BenchmarkDriver::Config::Executable>]
11
+ :filters, # @param [Array<Regexp>]
12
+ :repeat_count, # @param [Integer]
13
+ :repeat_result, # @param [String]
14
+ :run_duration, # @param [Float]
15
+ :timeout, # @param [Float,nil]
16
+ :verbose, # @param [Integer]
17
+ defaults: {
18
+ runner_type: 'ips',
19
+ output_type: 'compare',
20
+ filters: [],
21
+ repeat_count: 1,
22
+ repeat_result: 'best',
23
+ run_duration: 3.0,
24
+ verbose: 0,
25
+ },
26
+ )
27
+
28
+ # Subset of FullConfig passed to JobRunner
29
+ Config::RunnerConfig = ::BenchmarkDriver::Struct.new(
30
+ :repeat_count, # @param [Integer]
31
+ :repeat_result, # @param [String]
32
+ :run_duration, # @param [Float]
33
+ :timeout, # @param [Float,nil]
34
+ :verbose, # @param [Integer]
35
+ )
36
+
37
+ Config::Executable = ::BenchmarkDriver::Struct.new(
38
+ :name, # @param [String]
39
+ :command, # @param [Array<String>]
40
+ ) do
41
+ def initialize(*)
42
+ super
43
+ @cache = {} # modifiable storage even after `#freeze`
44
+ end
45
+
46
+ # @return [String] - Return result of `ruby -v`. This is for convenience of output plugins.
47
+ def description
48
+ @cache[:description] ||= IO.popen([*command, '-v'], &:read).rstrip
49
+ end
50
+
51
+ # @return [String] - Return RUBY_VERSION
52
+ def version
53
+ @cache[:version] ||= IO.popen([*command, '-e', 'print RUBY_VERSION'], &:read)
54
+ end
55
+ end
56
+ Config.defaults[:executables] = [
57
+ BenchmarkDriver::Config::Executable.new(name: RUBY_VERSION, command: [RbConfig.ruby]),
58
+ ]
59
+ end