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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9edbfd97d6566e4b2a73a54020d1a4ccccdcbb1dbc65f771d8c58b527868ec5e
4
- data.tar.gz: 1e5b06ca102234793875f50e37f9424ac1a977b91922e4662fb1552d90f14bb2
3
+ metadata.gz: 1f466d21a414cdea4c453ef9b013370b1ef383dfc9cef095ce3b9d56b3c51c87
4
+ data.tar.gz: c11050797b81cea16ae8520dd42e5c62480e633f492b9d60034d20c3759a124b
5
5
  SHA512:
6
- metadata.gz: 890807ab0362d1e7db37baa79dea67a0a502c1cdb5debf66bef70d7d8688818068603500dc23e9308f0cc931a1ccf77b7db17fce10a6893d1cd5a518596acde9
7
- data.tar.gz: d15d49fb4f467fd70345411d6a146acf55248a5698f396d05eba780f3ddf620d77a002e9690db9e4447e87c642570628ba79d4a93cc495f3283b3011ecf0e3d3
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: Feb 14, 2023
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 = <<~"".scan(/(\d+)(?:\/(\d+))?=(\w+)/).inject({}) do |ansi, (code, undo, name)|
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
- [0, Infinity].include?(show) and abort Overflow
201
- show *= 1000.0 and slot += 1 while show > 0 && show < 1.0
202
- show /= 1000.0 and slot -= 1 while show >= 1000.0
203
- slot.between?(0, 6) or abort Overflow
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
- # read the winr script
229
- winr = ARGV.first or abort "missing winr script"
249
+ # compile the template
230
250
  tmpl = ERB.new(template)
231
251
 
232
- # grok the config
233
- $config = eval(File.read(winr))
234
- es = $config.environments || [{}]
235
- cs = $config.contexts || [{}]
236
- ts = $config.tasks || [{}]
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
- # show the comparison
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
@@ -0,0 +1,10 @@
1
+ begin: |-
2
+ require "strscan"
3
+ scanner = StringScanner.new("test string")
4
+ tasks:
5
+ regexp_pattern: |
6
+ scanner.scan(/\w/)
7
+ regexp_literal: |
8
+ scanner.scan(/test/)
9
+ string: |
10
+ scanner.scan("test")
data/test/sum.rb CHANGED
@@ -14,7 +14,14 @@
14
14
  begin: <<~"|",
15
15
  require "digest/md5"
16
16
 
17
- max = 1e5.to_i
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: 3,
44
+ warmup: 2,
38
45
  }
data/winr.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "winr"
5
- s.version = "1.0.6"
5
+ s.version = `grep -m 1 '^\s*@version' bin/winr | cut -f 2 -d '"'`
6
6
  s.author = "Steve Shreeve"
7
7
  s.email = "steve.shreeve@gmail.com"
8
8
  s.summary =
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.6
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-02-18 00:00:00.000000000 Z
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.6
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