winr 1.0.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/winr +54 -21
- data/bin/winr-scan.rb +24 -0
- data/bin/winr.yaml +10 -0
- data/test/sum.rb +9 -2
- data/winr.gemspec +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f466d21a414cdea4c453ef9b013370b1ef383dfc9cef095ce3b9d56b3c51c87
|
4
|
+
data.tar.gz: c11050797b81cea16ae8520dd42e5c62480e633f492b9d60034d20c3759a124b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c1796a055f9070506c0b35dac80f27e547dbc490d7a5609660feb19496488bf959ff41f6f18b214aea512e775245773dadff53a5bcf95306dd49dcf810935fb
|
7
|
+
data.tar.gz: 02ccbab2deaa98fcefa060a04bd7304d5a8027c96f9a94e0e2897dde26c6a20d6f7159878f2abed813031a8ad49dad5323cc4770992cab72b606154a028a0dd6
|
data/bin/winr
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# winr - A quick and lightweight benchmarking tool for Ruby
|
5
5
|
#
|
6
6
|
# Author: Steve Shreeve (steve.shreeve@gmail.com)
|
7
|
-
# Date:
|
7
|
+
# Date: June 28, 2023
|
8
8
|
# ============================================================================
|
9
9
|
# GOALS:
|
10
10
|
# 1. Provide a simple way to benchmark code
|
@@ -20,9 +20,11 @@ trap("INT") { abort "\n" }
|
|
20
20
|
require "erb"
|
21
21
|
require "optparse"
|
22
22
|
require "shellwords"
|
23
|
+
require "yaml"
|
23
24
|
require "tempfile"
|
24
25
|
|
25
26
|
OptionParser.new.instance_eval do
|
27
|
+
@version = "1.2.0"
|
26
28
|
@banner = "usage: #{program_name} [options] <dir ...>"
|
27
29
|
|
28
30
|
on "-c" , "--[no-]color", "Enable color output (default is true)", TrueClass
|
@@ -43,6 +45,8 @@ OptionParser.new.instance_eval do
|
|
43
45
|
time time to run all iterations
|
44
46
|
end
|
45
47
|
|
48
|
+
Kernel.abort to_s if ARGV.empty?
|
49
|
+
|
46
50
|
self
|
47
51
|
end.parse!(into: opts={}) rescue abort($!.message)
|
48
52
|
|
@@ -60,13 +64,10 @@ show.empty? and abort "invalid list of statistics #{opts[:stats].inspect}"
|
|
60
64
|
|
61
65
|
# ==[ Define some constants, ansi codes, and make hashes more flexible ]==
|
62
66
|
|
63
|
-
# used by the scale() method below
|
64
|
-
Infinity = 1.0 / 0
|
65
|
-
Overflow = "\n\nERROR: numeric overflow"
|
66
67
|
|
67
68
|
module Ansi
|
68
69
|
refine String do
|
69
|
-
$ansi
|
70
|
+
$ansi ||= <<~"".scan(/(\d+)(?:\/(\d+))?=(\w+)/).inject({}) do |ansi, (code, undo, name)|
|
70
71
|
0=reset 1/22=bold 2/22=dim 3/23=italic 4/24=under 5/25=blink 7/27=inverse 9/29=strike
|
71
72
|
30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white 39=default
|
72
73
|
40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white 49=default
|
@@ -175,10 +176,30 @@ end
|
|
175
176
|
|
176
177
|
# ==[ Helpers ]==
|
177
178
|
|
179
|
+
# ┌───┬───┐ ╔═══╦═══╗ ╓───╥───╖ ╒═══╤═══╕ ╭────╮
|
180
|
+
# │ │ │ ║ ║ ║ ║ ║ ║ │ │ │ │test│
|
181
|
+
# ├───┼───┤ ╠═══╬═══╣ ╟───╫───╢ ╞═══╪═══╡ ╰────╯
|
182
|
+
# │ │ │ ║ ║ ║ ║ ║ ║ │ │ │
|
183
|
+
# └───┴───┘ ╚═══╩═══╝ ╙───╨───╜ ╘═══╧═══╛
|
184
|
+
|
185
|
+
# Returns box top, middle, and bottom rows, as follows:
|
186
|
+
#
|
187
|
+
# main = width of main column
|
188
|
+
# cols = array of data column widths
|
189
|
+
# runs = count of data column repeats
|
190
|
+
#
|
191
|
+
# For example: puts boxlines(10, [3,4,5], 2)
|
192
|
+
#
|
193
|
+
# ╭────────────┬────────────────────┬────────────────────╮ <= top # returned here
|
194
|
+
# │ 1234567890 │ Instance 1 │ Instance 2 │ <= HEADER # generated in your code
|
195
|
+
# ├────────────┼─────┬──────┬───────┼─────┬──────┬───────┤ <= middle # returned here
|
196
|
+
# │ 1234567890 │ 123 │ 1234 │ 12345 │ 123 │ 1234 │ 12345 │ <= CONTENT # generated in your code
|
197
|
+
# ╰────────────┴─────┴──────┴───────┴─────┴──────┴───────╯ <= bottom # returned here
|
198
|
+
|
178
199
|
def boxlines(main, cols, runs=1)
|
179
|
-
[ "
|
200
|
+
[ "╭┬──╮",
|
180
201
|
"├┼┬─┤",
|
181
|
-
"
|
202
|
+
"╰┴┴─╯" ]
|
182
203
|
.map do |str|
|
183
204
|
list = [main, *(cols * runs)]
|
184
205
|
list.map.with_index do |col, i|
|
@@ -194,14 +215,14 @@ def execute(command, path)
|
|
194
215
|
eval(File.read(path))
|
195
216
|
end
|
196
217
|
|
197
|
-
def scale(show, unit)
|
218
|
+
def scale(show, unit, base=1000)
|
219
|
+
base = base.to_f
|
198
220
|
slot = 3
|
199
221
|
span = ["G", "M", "K", " ", "m", "µ", "n"]
|
200
|
-
|
201
|
-
show *=
|
202
|
-
show /=
|
203
|
-
slot.between?(0, 6)
|
204
|
-
"%6.2f %s%s" % [show, span[slot], unit]
|
222
|
+
show.zero? and return "(overflow)"
|
223
|
+
show *= base and slot += 1 while show > 0 && show < 1.0
|
224
|
+
show /= base and slot -= 1 while show >= base
|
225
|
+
slot.between?(0, 6) ? "%6.2f %s%s" % [show, span[slot], unit] : "(overflow)"
|
205
226
|
end
|
206
227
|
|
207
228
|
def stats(list, scope=nil)
|
@@ -225,15 +246,24 @@ end
|
|
225
246
|
|
226
247
|
# ==[ Workflow ]==
|
227
248
|
|
228
|
-
#
|
229
|
-
winr = ARGV.first or abort "missing winr script"
|
249
|
+
# compile the template
|
230
250
|
tmpl = ERB.new(template)
|
231
251
|
|
232
|
-
#
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
252
|
+
# read the winr script
|
253
|
+
winr = ARGV.first or abort "missing script"
|
254
|
+
case File.extname(winr)
|
255
|
+
when ".yaml"
|
256
|
+
$config = YAML.load(File.read(winr))
|
257
|
+
es = [ {} ]
|
258
|
+
cs = [ begin: $config["begin"] ]
|
259
|
+
ts = $config["tasks"].map {|k,v| { name: k, script: v } }
|
260
|
+
when ".rb"
|
261
|
+
$config = eval(File.read(winr))
|
262
|
+
es = $config.environments || [{}]
|
263
|
+
cs = $config.contexts || [{}]
|
264
|
+
ts = $config.tasks || [{}]
|
265
|
+
else abort "unknown script format '#{winr}'"
|
266
|
+
end rescue abort "unable to read script '#{winr}'"
|
237
267
|
|
238
268
|
# adjust script fields, if needed
|
239
269
|
[*es, *cs].each do |item|
|
@@ -294,7 +324,9 @@ es.each_with_index do |e, ei|
|
|
294
324
|
puts rb, ""
|
295
325
|
end
|
296
326
|
|
297
|
-
#
|
327
|
+
# ==[ Performance comparison ]==
|
328
|
+
|
329
|
+
# header
|
298
330
|
rank.sort! {|a, b| b[0] <=> a[0] }
|
299
331
|
fast = rank.first[0]
|
300
332
|
slow = rank.last[0]
|
@@ -308,6 +340,7 @@ rh = "│ %-*.*s │" % [wide, wide, "Rank"]
|
|
308
340
|
rh << " %-*.*s │" % [full, full, "Performance".center(full)]
|
309
341
|
puts rt, rh, rm
|
310
342
|
|
343
|
+
# results
|
311
344
|
flip = cs.size > 1 && ts.size == 1
|
312
345
|
rank.each do |ips, ei, ci, ti|
|
313
346
|
name = (flip ? cs[ci] : ts[ti]).name
|
data/bin/winr-scan.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
contexts: [
|
3
|
+
{
|
4
|
+
begin: <<~"|".strip
|
5
|
+
require "strscan"
|
6
|
+
scanner = StringScanner.new("test string")
|
7
|
+
|
|
8
|
+
}
|
9
|
+
],
|
10
|
+
tasks: [
|
11
|
+
{
|
12
|
+
name: "regexp_pattern",
|
13
|
+
script: 'scanner.scan(/\w/)'
|
14
|
+
},
|
15
|
+
{
|
16
|
+
name: "regexp_literal",
|
17
|
+
script: 'scanner.scan(/test/)'
|
18
|
+
},
|
19
|
+
{
|
20
|
+
name: "string",
|
21
|
+
script: 'scanner.scan("test")'
|
22
|
+
},
|
23
|
+
]
|
24
|
+
}
|
data/bin/winr.yaml
ADDED
data/test/sum.rb
CHANGED
@@ -14,7 +14,14 @@
|
|
14
14
|
begin: <<~"|",
|
15
15
|
require "digest/md5"
|
16
16
|
|
17
|
-
max =
|
17
|
+
max = 5e4.to_i
|
18
|
+
|
|
19
|
+
},
|
20
|
+
{
|
21
|
+
begin: <<~"|",
|
22
|
+
require "digest/md5"
|
23
|
+
|
24
|
+
max = 1e3.to_i
|
18
25
|
|
|
19
26
|
},
|
20
27
|
],
|
@@ -34,5 +41,5 @@
|
|
34
41
|
|
|
35
42
|
},
|
36
43
|
],
|
37
|
-
warmup:
|
44
|
+
warmup: 2,
|
38
45
|
}
|
data/winr.gemspec
CHANGED
metadata
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A quick and lightweight benchmarking tool for Ruby
|
14
14
|
email: steve.shreeve@gmail.com
|
15
15
|
executables:
|
16
16
|
- winr
|
17
|
+
- winr-scan.rb
|
18
|
+
- winr.yaml
|
17
19
|
extensions: []
|
18
20
|
extra_rdoc_files: []
|
19
21
|
files:
|
@@ -21,6 +23,8 @@ files:
|
|
21
23
|
- LICENSE
|
22
24
|
- README.md
|
23
25
|
- bin/winr
|
26
|
+
- bin/winr-scan.rb
|
27
|
+
- bin/winr.yaml
|
24
28
|
- test/sum.rb
|
25
29
|
- winr.gemspec
|
26
30
|
homepage: https://github.com/shreeve/winr
|
@@ -42,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
requirements: []
|
45
|
-
rubygems_version: 3.4.
|
49
|
+
rubygems_version: 3.4.14
|
46
50
|
signing_key:
|
47
51
|
specification_version: 4
|
48
52
|
summary: A quick and lightweight benchmarking tool for Ruby
|