benchmark_driver 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +168 -0
- data/Rakefile +6 -0
- data/benchmark_driver.gemspec +28 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/bm_app_erb.yml +20 -0
- data/examples/erb_compile_render.yml +47 -0
- data/exe/benchmark_driver +36 -0
- data/lib/benchmark_driver.rb +223 -0
- data/lib/benchmark_driver/version.rb +3 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a09ccdd10d22d70ca190e43c4cdfa7bb6606f429
|
4
|
+
data.tar.gz: 6346d84cc347aa2111842e1b07c36138683c9d5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb5e63d89f0c344189467bde51efdd89a9a0e473eba30c15395d2c7f0e533f170ce164586b8c03a8e96f4cf89f5c804f0ff2f589e92b642e1b129ec00baccb8c
|
7
|
+
data.tar.gz: 87b3a29d42c3b6628e572741902739e7f104a0f00a21e0a24e44dc22edacc623f14dd2524db90083a398a7bb8540fbc9cb9b2ee0c6250c3708290a89a1e49298
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Takashi Kokubun
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# BenchmarkDriver
|
2
|
+
|
3
|
+
Benchmark driver for different Ruby executables
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install benchmark_driver
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```
|
12
|
+
$ benchmark_driver -h
|
13
|
+
Usage: benchmark_driver [options] [YAML]
|
14
|
+
-d, --duration [SECONDS] Duration seconds to run each benchmark (default: 1)
|
15
|
+
-e, --executables [EXECS] Ruby executables (e1::path1; e2::path2; e3::path3;...)
|
16
|
+
-r, --result-format=FORMAT Result output format [time|ips] (default: time)
|
17
|
+
-v, --verbose
|
18
|
+
```
|
19
|
+
|
20
|
+
### Running single script
|
21
|
+
|
22
|
+
With following `bm_app_erb.yml`,
|
23
|
+
|
24
|
+
```yml
|
25
|
+
prelude: |
|
26
|
+
require 'erb'
|
27
|
+
|
28
|
+
title = "hello world!"
|
29
|
+
content = "hello world!\n" * 10
|
30
|
+
|
31
|
+
data = <<EOS
|
32
|
+
<html>
|
33
|
+
<head> <%= title %> </head>
|
34
|
+
<body>
|
35
|
+
<h1> <%= title %> </h1>
|
36
|
+
<p>
|
37
|
+
<%= content %>
|
38
|
+
</p>
|
39
|
+
</body>
|
40
|
+
</html>
|
41
|
+
EOS
|
42
|
+
|
43
|
+
benchmark: |
|
44
|
+
ERB.new(data).result(binding)
|
45
|
+
```
|
46
|
+
|
47
|
+
you can benchmark the script with multiple ruby executables.
|
48
|
+
|
49
|
+
```
|
50
|
+
$ benchmark_driver bm_app_erb.yml -e ruby1::ruby -e ruby2::ruby
|
51
|
+
benchmark results:
|
52
|
+
Execution time (sec)
|
53
|
+
name ruby1 ruby2
|
54
|
+
bm_app_erb 1.028 1.010
|
55
|
+
|
56
|
+
Speedup ratio: compare with the result of `ruby1' (greater is better)
|
57
|
+
name ruby2
|
58
|
+
bm_app_erb 1.018
|
59
|
+
```
|
60
|
+
|
61
|
+
And you can change benchmark output by `-r` option.
|
62
|
+
|
63
|
+
```
|
64
|
+
$ benchmark_driver bm_app_erb.yml -e ruby1::ruby -e ruby2::ruby -r ips
|
65
|
+
Result -------------------------------------------
|
66
|
+
ruby1 ruby2
|
67
|
+
bm_app_erb 16082.8 i/s 15541.7 i/s
|
68
|
+
|
69
|
+
Comparison: bm_app_erb
|
70
|
+
ruby1: 16082.8 i/s
|
71
|
+
ruby2: 15541.7 i/s - 1.03x slower
|
72
|
+
```
|
73
|
+
|
74
|
+
### Running multiple scripts
|
75
|
+
|
76
|
+
One YAML file can contain multiple benchmark scripts.
|
77
|
+
With following `erb_compile_render.yml`,
|
78
|
+
|
79
|
+
```yml
|
80
|
+
- name: erb_compile
|
81
|
+
prelude: |
|
82
|
+
require 'erb'
|
83
|
+
|
84
|
+
title = "hello world!"
|
85
|
+
content = "hello world!\n" * 10
|
86
|
+
|
87
|
+
data = <<EOS
|
88
|
+
<html>
|
89
|
+
<head> <%= title %> </head>
|
90
|
+
<body>
|
91
|
+
<h1> <%= title %> </h1>
|
92
|
+
<p>
|
93
|
+
<%= content %>
|
94
|
+
</p>
|
95
|
+
</body>
|
96
|
+
</html>
|
97
|
+
EOS
|
98
|
+
|
99
|
+
benchmark: |
|
100
|
+
ERB.new(data).src
|
101
|
+
|
102
|
+
- name: erb_render
|
103
|
+
prelude: |
|
104
|
+
require 'erb'
|
105
|
+
|
106
|
+
title = "hello world!"
|
107
|
+
content = "hello world!\n" * 10
|
108
|
+
|
109
|
+
data = <<EOS
|
110
|
+
<html>
|
111
|
+
<head> <%= title %> </head>
|
112
|
+
<body>
|
113
|
+
<h1> <%= title %> </h1>
|
114
|
+
<p>
|
115
|
+
<%= content %>
|
116
|
+
</p>
|
117
|
+
</body>
|
118
|
+
</html>
|
119
|
+
EOS
|
120
|
+
|
121
|
+
src = "def self.render(title, content); #{ERB.new(data).src}; end"
|
122
|
+
mod = Module.new
|
123
|
+
mod.instance_eval(src, "(ERB)")
|
124
|
+
|
125
|
+
benchmark: |
|
126
|
+
mod.render(title, content)
|
127
|
+
```
|
128
|
+
|
129
|
+
you can benchmark the scripts with multiple ruby executables.
|
130
|
+
|
131
|
+
```
|
132
|
+
$ benchmark_driver erb_compile_render.yml -e ruby1::ruby -e ruby2::ruby
|
133
|
+
benchmark results:
|
134
|
+
Execution time (sec)
|
135
|
+
name ruby1 ruby2
|
136
|
+
erb_compile 0.987 0.985
|
137
|
+
erb_render 0.834 0.809
|
138
|
+
|
139
|
+
Speedup ratio: compare with the result of `ruby1' (greater is better)
|
140
|
+
name ruby2
|
141
|
+
erb_compile 1.002
|
142
|
+
erb_render 1.031
|
143
|
+
```
|
144
|
+
|
145
|
+
```
|
146
|
+
$ benchmark_driver erb_compile_render.yml -e ruby1::ruby -e ruby2::ruby -r ips
|
147
|
+
Result -------------------------------------------
|
148
|
+
ruby1 ruby2
|
149
|
+
erb_compile 30374.0 i/s 30832.1 i/s
|
150
|
+
erb_render 628403.5 i/s 624588.0 i/s
|
151
|
+
|
152
|
+
Comparison: erb_compile
|
153
|
+
ruby2: 30832.1 i/s
|
154
|
+
ruby1: 30374.0 i/s - 1.02x slower
|
155
|
+
|
156
|
+
Comparison: erb_render
|
157
|
+
ruby1: 628403.5 i/s
|
158
|
+
ruby2: 624588.0 i/s - 1.01x slower
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/k0kubun/benchmark_driver.
|
165
|
+
|
166
|
+
## License
|
167
|
+
|
168
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'benchmark_driver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'benchmark_driver'
|
8
|
+
spec.version = BenchmarkDriver::VERSION
|
9
|
+
spec.authors = ['Takashi Kokubun']
|
10
|
+
spec.email = ['takashikkbn@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Benchmark driver for different Ruby executables}
|
13
|
+
spec.description = %q{Benchmark driver for different Ruby executables}
|
14
|
+
spec.homepage = 'https://github.com/k0kubun/benchmark_driver'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
spec.required_ruby_version = '>= 2.3.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec'
|
28
|
+
end
|
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
prelude: |
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
title = "hello world!"
|
5
|
+
content = "hello world!\n" * 10
|
6
|
+
|
7
|
+
data = <<EOS
|
8
|
+
<html>
|
9
|
+
<head> <%= title %> </head>
|
10
|
+
<body>
|
11
|
+
<h1> <%= title %> </h1>
|
12
|
+
<p>
|
13
|
+
<%= content %>
|
14
|
+
</p>
|
15
|
+
</body>
|
16
|
+
</html>
|
17
|
+
EOS
|
18
|
+
|
19
|
+
benchmark: |
|
20
|
+
ERB.new(data).result(binding)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
- name: erb_compile
|
2
|
+
prelude: |
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
title = "hello world!"
|
6
|
+
content = "hello world!\n" * 10
|
7
|
+
|
8
|
+
data = <<EOS
|
9
|
+
<html>
|
10
|
+
<head> <%= title %> </head>
|
11
|
+
<body>
|
12
|
+
<h1> <%= title %> </h1>
|
13
|
+
<p>
|
14
|
+
<%= content %>
|
15
|
+
</p>
|
16
|
+
</body>
|
17
|
+
</html>
|
18
|
+
EOS
|
19
|
+
|
20
|
+
benchmark: |
|
21
|
+
ERB.new(data).src
|
22
|
+
|
23
|
+
- name: erb_render
|
24
|
+
prelude: |
|
25
|
+
require 'erb'
|
26
|
+
|
27
|
+
title = "hello world!"
|
28
|
+
content = "hello world!\n" * 10
|
29
|
+
|
30
|
+
data = <<EOS
|
31
|
+
<html>
|
32
|
+
<head> <%= title %> </head>
|
33
|
+
<body>
|
34
|
+
<h1> <%= title %> </h1>
|
35
|
+
<p>
|
36
|
+
<%= content %>
|
37
|
+
</p>
|
38
|
+
</body>
|
39
|
+
</html>
|
40
|
+
EOS
|
41
|
+
|
42
|
+
src = "def self.render(title, content); #{ERB.new(data).src}; end"
|
43
|
+
mod = Module.new
|
44
|
+
mod.instance_eval(src, "(ERB)")
|
45
|
+
|
46
|
+
benchmark: |
|
47
|
+
mod.render(title, content)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.expand_path('../lib', __dir__)
|
3
|
+
|
4
|
+
require 'benchmark_driver'
|
5
|
+
require 'optparse'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
args = OptionParser.new do |o|
|
10
|
+
o.banner = "Usage: #{File.basename($0, '.*')} [options] [YAML]"
|
11
|
+
o.on('-d', '--duration [SECONDS]', 'Duration seconds to run each benchmark (default: 1)') do |n|
|
12
|
+
options[:duration] = n.to_i
|
13
|
+
end
|
14
|
+
o.on('-e', '--executables [EXECS]', 'Ruby executables (e1::path1; e2::path2; e3::path3;...)') do |e|
|
15
|
+
options[:execs] ||= []
|
16
|
+
e.split(/;/).each do |path|
|
17
|
+
options[:execs] << path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
o.on('-r', "--result-format=FORMAT", "Result output format [time|ips] (default: time)", %w[time ips]) do |r|
|
21
|
+
options[:result_format] = r
|
22
|
+
end
|
23
|
+
o.on('-v', '--verbose') do |v|
|
24
|
+
options[:verbose] = v
|
25
|
+
end
|
26
|
+
end.parse!(ARGV)
|
27
|
+
abort "No YAML file is specified" if args.empty?
|
28
|
+
|
29
|
+
driver = BenchmarkDriver.new(options)
|
30
|
+
args.each do |yaml|
|
31
|
+
benchmarks = YAML.load(File.read(yaml))
|
32
|
+
if benchmarks.is_a?(Hash)
|
33
|
+
benchmarks[:name] = File.basename(yaml, '.*')
|
34
|
+
end
|
35
|
+
driver.run(benchmarks)
|
36
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require 'benchmark_driver/version'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
class BenchmarkDriver
|
6
|
+
# @param [Integer] duration - Benchmark duration in seconds
|
7
|
+
# @param [Array<String>] execs - ["path1", "path2"] or `["ruby1::path1", "ruby2::path2"]`
|
8
|
+
# @param [String] result_format
|
9
|
+
# @param [Boolean] verbose
|
10
|
+
def initialize(duration: 1, execs: ['ruby'], result_format: 'time', verbose: false)
|
11
|
+
@duration = duration
|
12
|
+
@execs = execs.map do |exec|
|
13
|
+
name, path = exec.split('::', 2)
|
14
|
+
Executable.new(name, path || name)
|
15
|
+
end
|
16
|
+
@result_format = result_format
|
17
|
+
@verbose = verbose
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [Hash,Array<Hash>] hashes
|
21
|
+
def run(hashes)
|
22
|
+
hashes = [hashes] if hashes.is_a?(Hash)
|
23
|
+
benchmarks = hashes.map do |hash|
|
24
|
+
BenchmarkScript.new(Hash[hash.map { |k, v| [k.to_sym, v] }])
|
25
|
+
end
|
26
|
+
if benchmarks.empty?
|
27
|
+
abort 'No benchmark is specified in YAML'
|
28
|
+
end
|
29
|
+
|
30
|
+
results = benchmarks.map do |benchmark|
|
31
|
+
metrics_by_exec = {}
|
32
|
+
iterations = calc_iterations(@execs.first, benchmark)
|
33
|
+
@execs.each do |exec|
|
34
|
+
puts "Running #{benchmark.name.dump} with #{exec.name.dump} #{iterations} times..." if @verbose
|
35
|
+
elapsed_time = run_benchmark(exec, benchmark, iterations)
|
36
|
+
metrics_by_exec[exec] = BenchmarkMetrics.new(iterations, elapsed_time)
|
37
|
+
end
|
38
|
+
BenchmarkResult.new(benchmark.name, metrics_by_exec)
|
39
|
+
end
|
40
|
+
puts if @verbose
|
41
|
+
|
42
|
+
case @result_format
|
43
|
+
when 'time'
|
44
|
+
ExecutionTimeReporter.report(@execs, results)
|
45
|
+
when 'ips'
|
46
|
+
IpsReporter.report(@execs, results)
|
47
|
+
else
|
48
|
+
raise "unsupported result format: #{@result_format.dump}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Estimate iterations to finish benchmark within `@duration`.
|
55
|
+
def calc_iterations(exec, benchmark)
|
56
|
+
# TODO: Change to try from 1, 10, 100 ...
|
57
|
+
base = 1000
|
58
|
+
time = run_benchmark(exec, benchmark, base)
|
59
|
+
(@duration / time * base).to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
def run_benchmark(exec, benchmark, iterations)
|
63
|
+
# TODO: raise error if negative
|
64
|
+
measure_script(exec.path, benchmark.benchmark_script(iterations)) -
|
65
|
+
measure_script(exec.path, benchmark.overhead_script(iterations))
|
66
|
+
end
|
67
|
+
|
68
|
+
def measure_script(ruby, script)
|
69
|
+
Tempfile.create do |f|
|
70
|
+
f.write(script)
|
71
|
+
f.close
|
72
|
+
|
73
|
+
cmd = "#{ruby} #{f.path}"
|
74
|
+
Benchmark.measure { system(cmd, out: File::NULL) }.real
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class BenchmarkScript
|
79
|
+
# @param [String] name
|
80
|
+
# @param [String] prelude
|
81
|
+
# @param [String] script
|
82
|
+
def initialize(name:, prelude: '', benchmark:)
|
83
|
+
@name = name
|
84
|
+
@prelude = prelude
|
85
|
+
@benchmark = benchmark
|
86
|
+
end
|
87
|
+
attr_reader :name
|
88
|
+
|
89
|
+
def overhead_script(iterations)
|
90
|
+
<<-RUBY
|
91
|
+
#{@prelude}
|
92
|
+
i = 0
|
93
|
+
while i < #{iterations}
|
94
|
+
i += 1
|
95
|
+
end
|
96
|
+
RUBY
|
97
|
+
end
|
98
|
+
|
99
|
+
def benchmark_script(iterations)
|
100
|
+
<<-RUBY
|
101
|
+
#{@prelude}
|
102
|
+
i = 0
|
103
|
+
while i < #{iterations}
|
104
|
+
i += 1
|
105
|
+
#{@benchmark}
|
106
|
+
end
|
107
|
+
RUBY
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class BenchmarkResult < Struct.new(
|
112
|
+
:name, # @param [String]
|
113
|
+
:metrics_by_exec, # @param [Hash{ Executable => BenchmarkMetrics }]
|
114
|
+
)
|
115
|
+
def iterations_of(exec)
|
116
|
+
metrics_by_exec.fetch(exec).iterations
|
117
|
+
end
|
118
|
+
|
119
|
+
def elapsed_time_of(exec)
|
120
|
+
metrics_by_exec.fetch(exec).elapsed_time
|
121
|
+
end
|
122
|
+
|
123
|
+
def ips_of(exec)
|
124
|
+
iterations_of(exec) / elapsed_time_of(exec)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class BenchmarkMetrics < Struct.new(
|
129
|
+
:iterations, # @param [Integer]
|
130
|
+
:elapsed_time, # @param [Float] - Elapsed time in seconds
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
class Executable < Struct.new(
|
135
|
+
:name, # @param [String]
|
136
|
+
:path, # @param [String]
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
module ExecutionTimeReporter
|
141
|
+
class << self
|
142
|
+
# @param [Array<Executable>] execs
|
143
|
+
# @param [Array<BenchmarkResult>] results
|
144
|
+
def report(execs, results)
|
145
|
+
puts "benchmark results:"
|
146
|
+
puts "Execution time (sec)"
|
147
|
+
puts "#{'%-16s' % 'name'} #{execs.map { |e| "%-8s" % e.name }.join(' ')}"
|
148
|
+
|
149
|
+
results.each do |result|
|
150
|
+
print '%-16s ' % result.name
|
151
|
+
puts execs.map { |exec|
|
152
|
+
"%-8s" % ("%.3f" % result.elapsed_time_of(exec))
|
153
|
+
}.join(' ')
|
154
|
+
end
|
155
|
+
puts
|
156
|
+
|
157
|
+
if execs.size > 1
|
158
|
+
report_speedup(execs, results)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
163
|
+
|
164
|
+
def report_speedup(execs, results)
|
165
|
+
compared = execs.first
|
166
|
+
rest = execs - [compared]
|
167
|
+
|
168
|
+
puts "Speedup ratio: compare with the result of `#{compared.name}' (greater is better)"
|
169
|
+
puts "#{'%-16s' % 'name'} #{rest.map { |e| "%-8s" % e.name }.join(' ')}"
|
170
|
+
results.each do |result|
|
171
|
+
print '%-16s ' % result.name
|
172
|
+
puts rest.map { |exec|
|
173
|
+
"%-8s" % ("%.3f" % (result.ips_of(exec) / result.ips_of(compared)))
|
174
|
+
}.join(' ')
|
175
|
+
end
|
176
|
+
puts
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
module IpsReporter
|
182
|
+
class << self
|
183
|
+
# @param [Array<Executable>] execs
|
184
|
+
# @param [Array<BenchmarkResult>] results
|
185
|
+
def report(execs, results)
|
186
|
+
puts "Result -------------------------------------------"
|
187
|
+
puts "#{' ' * 16} #{execs.map { |e| "%13s" % e.name }.join(' ')}"
|
188
|
+
|
189
|
+
results.each do |result|
|
190
|
+
print '%16s ' % result.name
|
191
|
+
puts execs.map { |exec|
|
192
|
+
"%13s" % ("%.1f i/s" % result.ips_of(exec))
|
193
|
+
}.join(' ')
|
194
|
+
end
|
195
|
+
puts
|
196
|
+
|
197
|
+
if execs.size > 1
|
198
|
+
compare(execs, results)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
private
|
203
|
+
|
204
|
+
def compare(execs, results)
|
205
|
+
results.each do |result|
|
206
|
+
puts "Comparison: #{result.name}"
|
207
|
+
|
208
|
+
sorted = execs.sort_by { |e| -result.ips_of(e) }
|
209
|
+
first = sorted.first
|
210
|
+
|
211
|
+
sorted.each do |exec|
|
212
|
+
if exec == first
|
213
|
+
puts "%16s: %12s i/s" % [first.name, "%.1f" % result.ips_of(first)]
|
214
|
+
else
|
215
|
+
puts "%16s: %12s i/s - %.2fx slower" % [exec.name, "%.1f" % result.ips_of(exec), result.ips_of(first) / result.ips_of(exec)]
|
216
|
+
end
|
217
|
+
end
|
218
|
+
puts
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benchmark_driver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi Kokubun
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Benchmark driver for different Ruby executables
|
56
|
+
email:
|
57
|
+
- takashikkbn@gmail.com
|
58
|
+
executables:
|
59
|
+
- benchmark_driver
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- benchmark_driver.gemspec
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- examples/bm_app_erb.yml
|
74
|
+
- examples/erb_compile_render.yml
|
75
|
+
- exe/benchmark_driver
|
76
|
+
- lib/benchmark_driver.rb
|
77
|
+
- lib/benchmark_driver/version.rb
|
78
|
+
homepage: https://github.com/k0kubun/benchmark_driver
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.3.0
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.11
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Benchmark driver for different Ruby executables
|
102
|
+
test_files: []
|