rubybench_runner 0.1.3 → 0.1.4
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/exe/rubybench_runner +29 -13
- data/lib/rubybench_runner.rb +5 -1
- data/lib/rubybench_runner/base_runner.rb +66 -25
- data/lib/rubybench_runner/rails_runner.rb +4 -0
- data/lib/rubybench_runner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4883f9435daeba8053226ff6256bd319f3af8f2200f3bfba7c96cb230fdd7e9b
|
4
|
+
data.tar.gz: 204755d83b2a496893bce8cb22c7288abeccd4ec44943d44c4703e90f57be32e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75f582c907dc3c795312be9fcd7f49adffd0d0f342d56fda1b06f88501aed0db1e32a8c530fa35b9d6e6737729dedce341874a43eba0ed788ba36e8300642fc6
|
7
|
+
data.tar.gz: ee1e4932c05689b15fadadaee4e20ed232b4e897051e354e81544992221af7d79a123eb75d6808048241bf75df10e975c35ecfda69f0ee5d02f50416602aaa3f
|
data/CHANGELOG.md
CHANGED
data/exe/rubybench_runner
CHANGED
@@ -4,10 +4,18 @@
|
|
4
4
|
$:.unshift File.expand_path('../lib', __dir__)
|
5
5
|
|
6
6
|
require 'rubybench_runner'
|
7
|
-
|
8
7
|
require 'optparse'
|
9
8
|
|
9
|
+
RUN = "run"
|
10
|
+
HELP = "help"
|
11
|
+
|
10
12
|
command = ARGV[0]
|
13
|
+
repo = ""
|
14
|
+
script = ""
|
15
|
+
|
16
|
+
if command == RUN
|
17
|
+
repo, script = ARGV[1].split("/", 2)
|
18
|
+
end
|
11
19
|
|
12
20
|
options = {}
|
13
21
|
OptionParser.new do |opts|
|
@@ -15,12 +23,11 @@ OptionParser.new do |opts|
|
|
15
23
|
Usage: rubybench_runner [command] [args] [options]
|
16
24
|
|
17
25
|
commands:
|
18
|
-
*
|
26
|
+
* #{RUN} <repo_name>/<script_name> [options]
|
19
27
|
<repo_name> is one the repos that are benchmarked on rubybench.org. Valid options are: `rails`
|
20
|
-
<
|
21
|
-
<local_path> is a path to your local clone of repo_name (e.g. ~/rails)
|
28
|
+
<script_name> is the name of the benchmark from rubybench.org e.g. bm_activerecord_finders_find_by_attributes.rb.
|
22
29
|
|
23
|
-
*
|
30
|
+
* #{HELP}
|
24
31
|
Show help
|
25
32
|
|
26
33
|
Available options:
|
@@ -43,7 +50,7 @@ OptionParser.new do |opts|
|
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
46
|
-
opts.on("-c", "--repeat-count=COUNT", Integer, "Number of times to run the benchmark (default
|
53
|
+
opts.on("-c", "--repeat-count=COUNT", Integer, "Number of times to run the benchmark (default 1)") do |c|
|
47
54
|
options[:repeat_count] = c
|
48
55
|
end
|
49
56
|
|
@@ -71,7 +78,7 @@ OptionParser.new do |opts|
|
|
71
78
|
options[:cleanup] = true
|
72
79
|
end
|
73
80
|
|
74
|
-
opts.on("
|
81
|
+
opts.on("--wps", "--with-prepared-statements", "Run benchmarks with prepared statements") do
|
75
82
|
options[:wps] = true
|
76
83
|
end
|
77
84
|
|
@@ -84,14 +91,23 @@ OptionParser.new do |opts|
|
|
84
91
|
puts opts
|
85
92
|
exit 0
|
86
93
|
end
|
94
|
+
|
95
|
+
opts.on("--url=URL", "Direct link to a benchmark script") do |url|
|
96
|
+
options[:url] = url
|
97
|
+
end
|
98
|
+
|
99
|
+
RubybenchRunner::SUPPORTED_REPOS.each do |name, _|
|
100
|
+
if repo == name.to_s
|
101
|
+
opts.on("--#{name}=PATH", "Provide local path to #{name}") do |path|
|
102
|
+
options[name] = File.expand_path(path)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
87
106
|
end.parse!
|
88
107
|
|
89
|
-
if command ==
|
90
|
-
|
91
|
-
|
92
|
-
repo_path = File.expand_path(ARGV[3])
|
93
|
-
RubybenchRunner.run(repo_name, script_url, repo_path, options)
|
94
|
-
elsif command == "help"
|
108
|
+
if command == RUN
|
109
|
+
RubybenchRunner.run(repo, script, options)
|
110
|
+
elsif command == HELP
|
95
111
|
puts opts
|
96
112
|
else
|
97
113
|
puts "Unknown command #{command}"
|
data/lib/rubybench_runner.rb
CHANGED
@@ -6,12 +6,16 @@ require 'yaml'
|
|
6
6
|
require 'fileutils'
|
7
7
|
require 'tmpdir'
|
8
8
|
require 'ostruct'
|
9
|
+
require 'open3'
|
9
10
|
|
10
11
|
require 'rubybench_runner/version'
|
11
|
-
require 'rubybench_runner/base_runner'
|
12
12
|
require 'rubybench_runner/dependencies_checker'
|
13
13
|
require 'rubybench_runner/configurations'
|
14
|
+
require 'rubybench_runner/base_runner'
|
14
15
|
require 'rubybench_runner/rails_runner'
|
15
16
|
|
16
17
|
module RubybenchRunner
|
18
|
+
SUPPORTED_REPOS = {
|
19
|
+
rails: RailsRunner
|
20
|
+
}
|
17
21
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module RubybenchRunner
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class ShellError < StandardError; end
|
3
|
+
|
4
|
+
def self.run(repo, script, opts = {})
|
5
|
+
SUPPORTED_REPOS.each do |name, klass|
|
6
|
+
if repo == name.to_s
|
7
|
+
klass.new(script, opts).run
|
8
|
+
return
|
9
|
+
end
|
7
10
|
end
|
8
|
-
|
11
|
+
raise "Unknown repo #{repo}"
|
9
12
|
end
|
10
13
|
|
11
14
|
class BaseRunner
|
@@ -27,18 +30,19 @@ module RubybenchRunner
|
|
27
30
|
round: 2
|
28
31
|
}
|
29
32
|
|
30
|
-
def initialize(
|
31
|
-
@
|
32
|
-
@repo_path = repo_path
|
33
|
+
def initialize(script, opts = {})
|
34
|
+
@script_name = script
|
33
35
|
@opts = OpenStruct.new(DEFAULT_OPTS.merge(opts))
|
36
|
+
@script_url = @opts.url || script_full_url(script)
|
34
37
|
@results = []
|
35
38
|
@error = nil
|
36
39
|
@output = ""
|
37
40
|
end
|
38
41
|
|
39
42
|
def run
|
40
|
-
|
43
|
+
set_repo_path
|
41
44
|
cleanup(before: true)
|
45
|
+
create_tmpdir
|
42
46
|
check_dependencies
|
43
47
|
write_gemfile
|
44
48
|
bundle_install
|
@@ -51,6 +55,33 @@ module RubybenchRunner
|
|
51
55
|
cleanup(after: true)
|
52
56
|
end
|
53
57
|
|
58
|
+
def possible_repo_path
|
59
|
+
File.join(Dir.home, benchmark_name.downcase)
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_repo_path_valid?
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_repo_path
|
67
|
+
name = benchmark_name.downcase
|
68
|
+
from_opts = false
|
69
|
+
if path = opts.send(name)
|
70
|
+
from_opts = true
|
71
|
+
@repo_path = path
|
72
|
+
else
|
73
|
+
@repo_path = possible_repo_path
|
74
|
+
log("Running #{name} benchmark #{@script_name}: #{name} path is #{possible_repo_path}\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
unless is_repo_path_valid?
|
78
|
+
output = "Cannot find #{name} at #{@repo_path}."
|
79
|
+
output += "Perhaps try:\n\nrubybench_runner run #{name}/#{@script_name} --#{name}=/path/to/#{name}" unless from_opts
|
80
|
+
log(output, f: true)
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
54
85
|
def dest_dir
|
55
86
|
# directory where all helpers and gems will be installed/copied to
|
56
87
|
@dest_dir ||= File.join(Dir.tmpdir, "rubybench_runner_tmp")
|
@@ -161,12 +192,17 @@ module RubybenchRunner
|
|
161
192
|
end
|
162
193
|
|
163
194
|
def run_benchmarks
|
195
|
+
return if @error
|
164
196
|
log("Running benchmarks...")
|
165
197
|
Dir.chdir(script_path) do
|
166
198
|
opts.repeat_count.times do |n|
|
167
|
-
res =
|
168
|
-
|
169
|
-
|
199
|
+
res, err = Open3.capture3(command)
|
200
|
+
if err.size == 0
|
201
|
+
@results[n] = res
|
202
|
+
@results[n] = JSON.parse(res)
|
203
|
+
else
|
204
|
+
raise ShellError.new(err)
|
205
|
+
end
|
170
206
|
end
|
171
207
|
end
|
172
208
|
rescue => err
|
@@ -193,18 +229,21 @@ module RubybenchRunner
|
|
193
229
|
if @error
|
194
230
|
@output = <<~OUTPUT
|
195
231
|
An error occurred while running the benchmarks:
|
196
|
-
Error: #{@error.message}
|
232
|
+
Error #{@error.class}: #{@error.message}
|
197
233
|
Backtrace:
|
198
234
|
#{@error.backtrace.join("\n")}
|
199
|
-
------
|
200
|
-
Raw results until this error:
|
201
|
-
#{@results}
|
202
235
|
OUTPUT
|
236
|
+
if @results.size > 0
|
237
|
+
@output += <<~OUTPUT
|
238
|
+
------
|
239
|
+
Raw results until this error:
|
240
|
+
#{@results}
|
241
|
+
OUTPUT
|
242
|
+
end
|
203
243
|
else
|
204
244
|
label = @results.first['label']
|
205
245
|
version = @results.first['version']
|
206
246
|
@output = "#{benchmark_name} version #{version}\n"
|
207
|
-
@output += "Benchmark name: #{label}\n"
|
208
247
|
@output += "Results (#{@results.size} runs):\n"
|
209
248
|
@results.map!.with_index do |res, ind|
|
210
249
|
res.delete('label')
|
@@ -245,6 +284,9 @@ module RubybenchRunner
|
|
245
284
|
log("Downloading script...")
|
246
285
|
content = open(script_url).read
|
247
286
|
File.write(script_full_path, content)
|
287
|
+
rescue OpenURI::HTTPError => e
|
288
|
+
log("Script download failed #{script_url}", f: true)
|
289
|
+
@error = e
|
248
290
|
end
|
249
291
|
|
250
292
|
def write_gemfile
|
@@ -254,8 +296,8 @@ module RubybenchRunner
|
|
254
296
|
|
255
297
|
private
|
256
298
|
|
257
|
-
def log(msg)
|
258
|
-
return if opts.quiet
|
299
|
+
def log(msg, f: false)
|
300
|
+
return if opts.quiet && !f
|
259
301
|
puts msg
|
260
302
|
end
|
261
303
|
|
@@ -272,12 +314,11 @@ module RubybenchRunner
|
|
272
314
|
FileUtils.rm_rf(dest_dir) if (opts.fresh_run && before) || (opts.cleanup && after)
|
273
315
|
end
|
274
316
|
|
275
|
-
def
|
276
|
-
if
|
277
|
-
|
278
|
-
else
|
279
|
-
url
|
317
|
+
def script_full_url(script)
|
318
|
+
if script !~ /\.rb$/
|
319
|
+
script += ".rb"
|
280
320
|
end
|
321
|
+
"https://raw.githubusercontent.com/ruby-bench/ruby-bench-suite/master/#{benchmark_name.downcase}/benchmarks/#{script}"
|
281
322
|
end
|
282
323
|
|
283
324
|
# small hack for dynamically installing/requiring gems.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubybench_runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Osama Sayegh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|