winr 1.1.0 → 1.2.0
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/bin/winr +40 -17
- data/bin/winr-scan.rb +0 -0
- data/bin/winr.yaml +0 -0
- data/test/sum.rb +9 -2
- data/winr.gemspec +1 -1
- metadata +3 -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
|
@@ -24,6 +24,7 @@ require "yaml"
|
|
24
24
|
require "tempfile"
|
25
25
|
|
26
26
|
OptionParser.new.instance_eval do
|
27
|
+
@version = "1.2.0"
|
27
28
|
@banner = "usage: #{program_name} [options] <dir ...>"
|
28
29
|
|
29
30
|
on "-c" , "--[no-]color", "Enable color output (default is true)", TrueClass
|
@@ -44,6 +45,8 @@ OptionParser.new.instance_eval do
|
|
44
45
|
time time to run all iterations
|
45
46
|
end
|
46
47
|
|
48
|
+
Kernel.abort to_s if ARGV.empty?
|
49
|
+
|
47
50
|
self
|
48
51
|
end.parse!(into: opts={}) rescue abort($!.message)
|
49
52
|
|
@@ -61,13 +64,10 @@ show.empty? and abort "invalid list of statistics #{opts[:stats].inspect}"
|
|
61
64
|
|
62
65
|
# ==[ Define some constants, ansi codes, and make hashes more flexible ]==
|
63
66
|
|
64
|
-
# used by the scale() method below
|
65
|
-
Infinity = 1.0 / 0
|
66
|
-
Overflow = "\n\nERROR: numeric overflow"
|
67
67
|
|
68
68
|
module Ansi
|
69
69
|
refine String do
|
70
|
-
$ansi
|
70
|
+
$ansi ||= <<~"".scan(/(\d+)(?:\/(\d+))?=(\w+)/).inject({}) do |ansi, (code, undo, name)|
|
71
71
|
0=reset 1/22=bold 2/22=dim 3/23=italic 4/24=under 5/25=blink 7/27=inverse 9/29=strike
|
72
72
|
30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white 39=default
|
73
73
|
40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white 49=default
|
@@ -176,10 +176,30 @@ end
|
|
176
176
|
|
177
177
|
# ==[ Helpers ]==
|
178
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
|
+
|
179
199
|
def boxlines(main, cols, runs=1)
|
180
|
-
[ "
|
200
|
+
[ "╭┬──╮",
|
181
201
|
"├┼┬─┤",
|
182
|
-
"
|
202
|
+
"╰┴┴─╯" ]
|
183
203
|
.map do |str|
|
184
204
|
list = [main, *(cols * runs)]
|
185
205
|
list.map.with_index do |col, i|
|
@@ -195,14 +215,14 @@ def execute(command, path)
|
|
195
215
|
eval(File.read(path))
|
196
216
|
end
|
197
217
|
|
198
|
-
def scale(show, unit)
|
218
|
+
def scale(show, unit, base=1000)
|
219
|
+
base = base.to_f
|
199
220
|
slot = 3
|
200
221
|
span = ["G", "M", "K", " ", "m", "µ", "n"]
|
201
|
-
|
202
|
-
show *=
|
203
|
-
show /=
|
204
|
-
slot.between?(0, 6)
|
205
|
-
"%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)"
|
206
226
|
end
|
207
227
|
|
208
228
|
def stats(list, scope=nil)
|
@@ -230,7 +250,7 @@ end
|
|
230
250
|
tmpl = ERB.new(template)
|
231
251
|
|
232
252
|
# read the winr script
|
233
|
-
winr = ARGV.first or abort "missing
|
253
|
+
winr = ARGV.first or abort "missing script"
|
234
254
|
case File.extname(winr)
|
235
255
|
when ".yaml"
|
236
256
|
$config = YAML.load(File.read(winr))
|
@@ -242,8 +262,8 @@ when ".rb"
|
|
242
262
|
es = $config.environments || [{}]
|
243
263
|
cs = $config.contexts || [{}]
|
244
264
|
ts = $config.tasks || [{}]
|
245
|
-
else abort "unknown
|
246
|
-
end
|
265
|
+
else abort "unknown script format '#{winr}'"
|
266
|
+
end rescue abort "unable to read script '#{winr}'"
|
247
267
|
|
248
268
|
# adjust script fields, if needed
|
249
269
|
[*es, *cs].each do |item|
|
@@ -304,7 +324,9 @@ es.each_with_index do |e, ei|
|
|
304
324
|
puts rb, ""
|
305
325
|
end
|
306
326
|
|
307
|
-
#
|
327
|
+
# ==[ Performance comparison ]==
|
328
|
+
|
329
|
+
# header
|
308
330
|
rank.sort! {|a, b| b[0] <=> a[0] }
|
309
331
|
fast = rank.first[0]
|
310
332
|
slow = rank.last[0]
|
@@ -318,6 +340,7 @@ rh = "│ %-*.*s │" % [wide, wide, "Rank"]
|
|
318
340
|
rh << " %-*.*s │" % [full, full, "Performance".center(full)]
|
319
341
|
puts rt, rh, rm
|
320
342
|
|
343
|
+
# results
|
321
344
|
flip = cs.size > 1 && ts.size == 1
|
322
345
|
rank.each do |ips, ei, ci, ti|
|
323
346
|
name = (flip ? cs[ci] : ts[ti]).name
|
data/bin/winr-scan.rb
CHANGED
File without changes
|
data/bin/winr.yaml
CHANGED
File without changes
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
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
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
|
-
rubygems_version: 3.4.
|
49
|
+
rubygems_version: 3.4.14
|
50
50
|
signing_key:
|
51
51
|
specification_version: 4
|
52
52
|
summary: A quick and lightweight benchmarking tool for Ruby
|