benchmark_driver 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/exe/benchmark-driver +1 -1
- data/lib/benchmark_driver/output/compare.rb +2 -0
- data/lib/benchmark_driver/runner.rb +1 -0
- data/lib/benchmark_driver/runner/ips.rb +1 -0
- data/lib/benchmark_driver/runner/memory.rb +4 -7
- data/lib/benchmark_driver/runner/once.rb +104 -0
- data/lib/benchmark_driver/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c1c86ab9c0e65de1f585af43bea8e331d9f1e4376e7f474ac06ffcb0550e282f
|
4
|
+
data.tar.gz: 1d644ecc22c43af0ae19c7d1c525fe1a12d45d56321803b2ba54e3f37c19311b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e1d5d9f65635161f9694feb3ad685d6006bf8fc83f68ef3133be18bbfe908e08c5f9fbf9546d1775a8be3016b709e4a24eecdc9d4b66cbb879b2d3f7273e94
|
7
|
+
data.tar.gz: 654e5d9a00e5547dfb1e4d110f1147440c829b0af58b995228b237b87bcec309d59cea7cfef94332c430956b2a757bf744c156a167aa3a593b414f733275c7f7
|
data/CHANGELOG.md
CHANGED
data/exe/benchmark-driver
CHANGED
@@ -12,7 +12,7 @@ config = BenchmarkDriver::Config.new.tap do |c|
|
|
12
12
|
bundler = false
|
13
13
|
parser = OptionParser.new do |o|
|
14
14
|
o.banner = "Usage: #{File.basename($0, '.*')} [options] [YAML]"
|
15
|
-
o.on('-r', '--runner [TYPE]', 'Specify runner type: ips, time, memory (default: ips)') do |d|
|
15
|
+
o.on('-r', '--runner [TYPE]', 'Specify runner type: ips, time, memory, once (default: ips)') do |d|
|
16
16
|
abort '-r, --runner must take argument but not given' if d.nil?
|
17
17
|
c.runner_type = d
|
18
18
|
end
|
@@ -5,6 +5,7 @@ require 'benchmark_driver/default_job_parser'
|
|
5
5
|
require 'tempfile'
|
6
6
|
require 'shellwords'
|
7
7
|
|
8
|
+
# Show iteration per second.
|
8
9
|
class BenchmarkDriver::Runner::Ips
|
9
10
|
# JobParser returns this, `BenchmarkDriver::Runner.runner_for` searches "*::Job"
|
10
11
|
Job = Class.new(BenchmarkDriver::DefaultJob)
|
@@ -72,10 +72,8 @@ class BenchmarkDriver::Runner::Memory
|
|
72
72
|
loop_count: job.loop_count,
|
73
73
|
)
|
74
74
|
|
75
|
-
output =
|
76
|
-
|
77
|
-
execute('/usr/bin/time', *exec.command, path)
|
78
|
-
end
|
75
|
+
output = with_script(benchmark.render) do |path|
|
76
|
+
execute('/usr/bin/time', *exec.command, path)
|
79
77
|
end
|
80
78
|
|
81
79
|
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)
|
@@ -108,11 +106,10 @@ class BenchmarkDriver::Runner::Memory
|
|
108
106
|
# @param [String] teardown
|
109
107
|
# @param [Integer] loop_count
|
110
108
|
BenchmarkScript = ::BenchmarkDriver::Struct.new(:prelude, :script, :teardown, :loop_count) do
|
111
|
-
|
112
|
-
def render(result:)
|
109
|
+
def render
|
113
110
|
<<-RUBY
|
114
111
|
#{prelude}
|
115
|
-
#{while_loop(
|
112
|
+
#{while_loop(script, loop_count)}
|
116
113
|
#{teardown}
|
117
114
|
RUBY
|
118
115
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'benchmark_driver/struct'
|
2
|
+
require 'benchmark_driver/metrics'
|
3
|
+
require 'benchmark_driver/default_job'
|
4
|
+
require 'benchmark_driver/default_job_parser'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'shellwords'
|
7
|
+
|
8
|
+
# Run only once, for testing
|
9
|
+
class BenchmarkDriver::Runner::Once
|
10
|
+
# JobParser returns this, `BenchmarkDriver::Runner.runner_for` searches "*::Job"
|
11
|
+
Job = Class.new(BenchmarkDriver::DefaultJob)
|
12
|
+
# Dynamically fetched and used by `BenchmarkDriver::JobParser.parse`
|
13
|
+
JobParser = BenchmarkDriver::DefaultJobParser.for(Job)
|
14
|
+
# Passed to `output` by `BenchmarkDriver::Runner.run`
|
15
|
+
MetricsType = BenchmarkDriver::Metrics::Type.new(unit: 'i/s')
|
16
|
+
|
17
|
+
# @param [BenchmarkDriver::Config::RunnerConfig] config
|
18
|
+
# @param [BenchmarkDriver::Output::*] output
|
19
|
+
def initialize(config:, output:)
|
20
|
+
@config = config
|
21
|
+
@output = output
|
22
|
+
end
|
23
|
+
|
24
|
+
# This method is dynamically called by `BenchmarkDriver::JobRunner.run`
|
25
|
+
# @param [Array<BenchmarkDriver::Default::Job>] jobs
|
26
|
+
def run(jobs)
|
27
|
+
jobs = jobs.map do |job|
|
28
|
+
Job.new(job.to_h.merge(loop_count: 1)) # to show this on output
|
29
|
+
end
|
30
|
+
|
31
|
+
@output.with_benchmark do
|
32
|
+
jobs.each do |job|
|
33
|
+
@output.with_job(job) do
|
34
|
+
@config.executables.each do |exec|
|
35
|
+
metrics = run_benchmark(job, exec: exec) # no repeat support
|
36
|
+
@output.report(metrics)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# @param [BenchmarkDriver::Runner::Ips::Job] job - loop_count is not nil
|
46
|
+
# @param [BenchmarkDriver::Config::Executable] exec
|
47
|
+
# @return [BenchmarkDriver::Metrics]
|
48
|
+
def run_benchmark(job, exec:)
|
49
|
+
benchmark = BenchmarkScript.new(
|
50
|
+
prelude: job.prelude,
|
51
|
+
script: job.script,
|
52
|
+
teardown: job.teardown,
|
53
|
+
loop_count: job.loop_count,
|
54
|
+
)
|
55
|
+
|
56
|
+
duration = Tempfile.open(['benchmark_driver-', '.rb']) do |f|
|
57
|
+
with_script(benchmark.render(result: f.path)) do |path|
|
58
|
+
execute(*exec.command, path)
|
59
|
+
end
|
60
|
+
Float(f.read)
|
61
|
+
end
|
62
|
+
|
63
|
+
BenchmarkDriver::Metrics.new(
|
64
|
+
value: 1.0 / duration,
|
65
|
+
duration: duration,
|
66
|
+
executable: exec,
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def with_script(script)
|
71
|
+
Tempfile.open(['benchmark_driver-', '.rb']) do |f|
|
72
|
+
f.puts script
|
73
|
+
f.close
|
74
|
+
return yield(f.path)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def execute(*args)
|
79
|
+
output = IO.popen(args, err: [:child, :out], &:read) # handle stdout?
|
80
|
+
unless $?.success?
|
81
|
+
raise "Failed to execute: #{args.shelljoin} (status: #{$?.exitstatus})"
|
82
|
+
end
|
83
|
+
output
|
84
|
+
end
|
85
|
+
|
86
|
+
# @param [String] prelude
|
87
|
+
# @param [String] script
|
88
|
+
# @param [String] teardown
|
89
|
+
# @param [Integer] loop_count
|
90
|
+
BenchmarkScript = ::BenchmarkDriver::Struct.new(:prelude, :script, :teardown, :loop_count) do
|
91
|
+
# @param [String] result - A file to write result
|
92
|
+
def render(result:)
|
93
|
+
<<-RUBY
|
94
|
+
#{prelude}
|
95
|
+
__bmdv_before = Time.now
|
96
|
+
#{script}
|
97
|
+
__bmdv_after = Time.now
|
98
|
+
File.write(#{result.dump}, (__bmdv_after - __bmdv_before).inspect)
|
99
|
+
#{teardown}
|
100
|
+
RUBY
|
101
|
+
end
|
102
|
+
end
|
103
|
+
private_constant :BenchmarkScript
|
104
|
+
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.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/benchmark_driver/runner.rb
|
84
84
|
- lib/benchmark_driver/runner/ips.rb
|
85
85
|
- lib/benchmark_driver/runner/memory.rb
|
86
|
+
- lib/benchmark_driver/runner/once.rb
|
86
87
|
- lib/benchmark_driver/runner/time.rb
|
87
88
|
- lib/benchmark_driver/struct.rb
|
88
89
|
- lib/benchmark_driver/version.rb
|
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.7.3
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Fully-featured accurate benchmark driver for Ruby
|