benchmark_driver-output-rubybench 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ac3b43d5332f007435fe219875e4c0da251038dcd12b12f87609c4b4d9d85f6
4
- data.tar.gz: 3a0c5c3dbaa42e4f1b4f0ef33259eb4db26bd098ac394b0615ab24a3ce92c557
3
+ metadata.gz: 60e1386301a2541d0ee52889e3015edb95500b7dd8730465d03df48cb1fd0f8c
4
+ data.tar.gz: 04cc7eae0ba531753f168a5171f0acc040ddb0b3597ba88cbc4f3c90609b6b38
5
5
  SHA512:
6
- metadata.gz: 71ebd1fd40794389827eb9b75bed3214232c5b4f1556dc8f52bf66110f5da32a82fa1654ed27c3bf2791cd97ac8aa33ccc041c79eb96c6d80811b31180ebf085
7
- data.tar.gz: a6695e9fc85824e4b1a60f839db328d784b166da2e88f871f938ddc43aca74ef30ab2b4914711d06e2bbb4b839081e7e33e1026ba10c82a91c05e4781d06a9ee
6
+ metadata.gz: 2691745beccb9e90f12cb4ec1a92cc18b8baccf33fa201a3ee38696b2eb1112eb447e10f67a8fd831aa205d7791e77c397bd47c5d6028c617094d4d926305c88
7
+ data.tar.gz: f6c550aac7af86ed6707c7a9fc2e4870d3a7b8644740018d2594d3a6ee3cd3db0e7f62437ab5294e86b41c815df6d7a5bfb25d2135e37c28272f00c3e483f8a4
@@ -1,7 +1,7 @@
1
1
  module BenchmarkDriver
2
2
  module Output
3
3
  class Rubybench
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,135 @@
1
+ require 'benchmark_driver/struct'
2
+ require 'benchmark_driver/metric'
3
+ require 'benchmark_driver/default_job'
4
+ require 'benchmark_driver/default_job_parser'
5
+ require 'tempfile'
6
+ require 'shellwords'
7
+
8
+ # Max resident set size
9
+ class BenchmarkDriver::Runner::Memory
10
+ # Using the RubyBench's original label
11
+ METRIC = BenchmarkDriver::Metric.new(
12
+ name: 'RSS memory usage', unit: 'Kilobytes', larger_better: false, worse_word: 'larger',
13
+ )
14
+
15
+ # JobParser returns this, `BenchmarkDriver::Runner.runner_for` searches "*::Job"
16
+ Job = Class.new(BenchmarkDriver::DefaultJob)
17
+ # Dynamically fetched and used by `BenchmarkDriver::JobParser.parse`
18
+ JobParser = BenchmarkDriver::DefaultJobParser.for(klass: Job, metrics: [METRIC])
19
+
20
+ # @param [BenchmarkDriver::Config::RunnerConfig] config
21
+ # @param [BenchmarkDriver::Output] output
22
+ # @param [BenchmarkDriver::Context] contexts
23
+ def initialize(config:, output:, contexts:)
24
+ @config = config
25
+ @output = output
26
+ @contexts = contexts
27
+ end
28
+
29
+ # This method is dynamically called by `BenchmarkDriver::JobRunner.run`
30
+ # @param [Array<BenchmarkDriver::Default::Job>] jobs
31
+ def run(jobs)
32
+ # Currently Linux's time(1) support only...
33
+ if Etc.uname.fetch(:sysname) != 'Linux'
34
+ raise "memory output is not supported for '#{Etc.uname[:sysname]}' for now"
35
+ end
36
+
37
+ if jobs.any? { |job| job.loop_count.nil? }
38
+ jobs = jobs.map do |job|
39
+ job.loop_count ? job : Job.new(job.to_h.merge(loop_count: 1))
40
+ end
41
+ end
42
+
43
+ @output.with_benchmark do
44
+ jobs.each do |job|
45
+ @output.with_job(name: job.name) do
46
+ job.runnable_contexts(@contexts).each do |context|
47
+ value = BenchmarkDriver::Repeater.with_repeat(config: @config, larger_better: false) do
48
+ run_benchmark(job, context: context)
49
+ end
50
+ @output.with_context(name: context.name, executable: context.executable, gems: context.gems, prelude: context.prelude) do
51
+ @output.report(values: { METRIC => value }, loop_count: job.loop_count)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ # @param [BenchmarkDriver::Runner::Ips::Job] job - loop_count is not nil
62
+ # @param [BenchmarkDriver::Context] context
63
+ # @return [BenchmarkDriver::Metrics]
64
+ def run_benchmark(job, context:)
65
+ benchmark = BenchmarkScript.new(
66
+ preludes: [context.prelude, job.prelude],
67
+ script: job.script,
68
+ teardown: job.teardown,
69
+ loop_count: job.loop_count,
70
+ )
71
+
72
+ with_script(benchmark.render) do |path|
73
+ output = IO.popen(['/usr/bin/time', *context.executable.command, path], err: [:child, :out], &:read)
74
+ if $?.success?
75
+ match_data = /^(?<user>\d+.\d+)user\s+(?<system>\d+.\d+)system\s+(?<elapsed1>\d+):(?<elapsed2>\d+.\d+)elapsed.+\([^\s]+\s+(?<maxresident>\d+)maxresident\)k$/.match(output)
76
+ raise "Unexpected format given from /usr/bin/time:\n#{out}" unless match_data[:maxresident]
77
+
78
+ Integer(match_data[:maxresident])
79
+ else
80
+ $stdout.print(output)
81
+ BenchmarkDriver::Result::ERROR
82
+ end
83
+ end
84
+ end
85
+
86
+ def with_script(script)
87
+ if @config.verbose >= 2
88
+ sep = '-' * 30
89
+ $stdout.puts "\n\n#{sep}[Script begin]#{sep}\n#{script}#{sep}[Script end]#{sep}\n\n"
90
+ end
91
+
92
+ Tempfile.open(['benchmark_driver-', '.rb']) do |f|
93
+ f.puts script
94
+ f.close
95
+ return yield(f.path)
96
+ end
97
+ end
98
+
99
+ # @param [String] prelude
100
+ # @param [String] script
101
+ # @param [String] teardown
102
+ # @param [Integer] loop_count
103
+ BenchmarkScript = ::BenchmarkDriver::Struct.new(:preludes, :script, :teardown, :loop_count) do
104
+ def render
105
+ prelude = preludes.reject(&:nil?).reject(&:empty?).join("\n")
106
+ <<-RUBY
107
+ #{prelude}
108
+ #{while_loop(script, loop_count)}
109
+ #{teardown}
110
+ RUBY
111
+ end
112
+
113
+ private
114
+
115
+ def while_loop(content, times)
116
+ if !times.is_a?(Integer) || times <= 0
117
+ raise ArgumentError.new("Unexpected times: #{times.inspect}")
118
+ end
119
+
120
+ # TODO: execute in batch
121
+ if times > 1
122
+ <<-RUBY
123
+ __bmdv_i = 0
124
+ while __bmdv_i < #{times}
125
+ #{content}
126
+ __bmdv_i += 1
127
+ end
128
+ RUBY
129
+ else
130
+ content
131
+ end
132
+ end
133
+ end
134
+ private_constant :BenchmarkScript
135
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark_driver-output-rubybench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
@@ -67,6 +67,7 @@ files:
67
67
  - benchmark_driver-output-rubybench.gemspec
68
68
  - lib/benchmark_driver/output/rubybench.rb
69
69
  - lib/benchmark_driver/output/rubybench/version.rb
70
+ - lib/benchmark_driver/runner/rsskb.rb
70
71
  - lib/benchmark_driver/runner/seconds.rb
71
72
  homepage: https://github.com/ruby-bench/ruby-bench-suite
72
73
  licenses: