benchmark-ips 2.11.0 → 2.12.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: 194a6da5977a23dc733ade6dadaefe1a7d7215678d6135ff33d5c37304bec993
4
- data.tar.gz: e072ffd46009a79e13990e7435e1415ec24fd0407f86d566208fc597b8e33f7d
3
+ metadata.gz: f5c89b6607d6960de72e63e6e14ee0283f2dbe3f2418f33d90b57e947f555d70
4
+ data.tar.gz: 5ee11f5ae33b1c426a90deba5799a739cd13d785d5ab7c4e4ffaa942d5ddc8db
5
5
  SHA512:
6
- metadata.gz: 5b3a8e41f223d3945daf11329e7cd68b1cc41f9b08b9f3f2e9e5a471a37134782f4e1f78caca102b7b3b08eb179ac4d78868bb1f97bfab4ac1ccef22aa38d42d
7
- data.tar.gz: e5cd27c03050929b8edf402264c0f5a32560550ee6d79456d2513ae9b4a76f763f669a32ba4cc3bf7a45e7c086426631c2ba26724a749192fc637046bfd6a495
6
+ metadata.gz: 52e1d308de07129514ff4c6c9848a0e68f074937ab2cd05b75060ac055655bc581f382041ddd21780439f682540fdb3ee5d041214a677dc87cd8a527b587bfe8
7
+ data.tar.gz: fbb5b4045f318f31772eb3e27cc6f49c1589d857d13c17d7e16c52d82be5253aef30b7c327f8f76f9e14cc3c81bd496423f1f043e8cd7287074a31466bd49b07
data/History.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 2.12.0 / 2023-03-08
2
+
3
+ * Feature
4
+ * Adds MultiReport and ability report to a stream rather than a string.
5
+
1
6
  ### 2.11.0 / 2023-02-15
2
7
 
3
8
  * Feature
@@ -0,0 +1,67 @@
1
+ module Benchmark
2
+ module IPS
3
+ class Job
4
+ class MultiReport
5
+ # @returns out [Array<StreamReport>] list of reports to send output
6
+ attr_accessor :out
7
+
8
+ def empty?
9
+ @out.empty?
10
+ end
11
+
12
+ def quiet?
13
+ @out.none? { |rpt| rpt.kind_of?(StreamReport) }
14
+ end
15
+
16
+ def quiet!
17
+ @out.delete_if { |rpt| rpt.kind_of?(StreamReport) }
18
+ end
19
+
20
+ # @param report [StreamReport] report to accept input?
21
+ def <<(report)
22
+ if report.kind_of?(MultiReport)
23
+ self << report.out
24
+ elsif report.kind_of?(Enumerable)
25
+ @out += report
26
+ elsif report
27
+ @out << report
28
+ end
29
+ end
30
+
31
+ # @param out [Array<StreamReport>] list of reports to send output
32
+ def initialize(out = nil)
33
+ @out = []
34
+ self << out
35
+ end
36
+
37
+ def start_warming
38
+ @out.each { |o| o.start_warming if o.respond_to?(:start_warming) }
39
+ end
40
+
41
+ def warming(label, warmup)
42
+ @out.each { |o| o.warming(label, warmup) }
43
+ end
44
+
45
+ def warmup_stats(warmup_time_us, timing)
46
+ @out.each { |o| o.warmup_stats(warmup_time_us, timing) }
47
+ end
48
+
49
+ def start_running
50
+ @out.each { |o| o.start_running if o.respond_to?(:start_running) }
51
+ end
52
+
53
+ def running(label, warmup)
54
+ @out.each { |o| o.running(label, warmup) }
55
+ end
56
+
57
+ def add_report(item, caller)
58
+ @out.each { |o| o.add_report(item, caller) }
59
+ end
60
+
61
+ def footer
62
+ @out.each { |o| o.footer if o.respond_to?(:footer) }
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,43 +1,44 @@
1
1
  module Benchmark
2
2
  module IPS
3
3
  class Job
4
- class StdoutReport
5
- def initialize
4
+ class StreamReport
5
+ def initialize(stream = $stdout)
6
6
  @last_item = nil
7
+ @out = stream
7
8
  end
8
9
 
9
10
  def start_warming
10
- $stdout.puts "Warming up --------------------------------------"
11
+ @out.puts "Warming up --------------------------------------"
11
12
  end
12
13
 
13
14
  def start_running
14
- $stdout.puts "Calculating -------------------------------------"
15
+ @out.puts "Calculating -------------------------------------"
15
16
  end
16
17
 
17
18
  def warming(label, _warmup)
18
- $stdout.print rjust(label)
19
+ @out.print rjust(label)
19
20
  end
20
21
 
21
22
  def warmup_stats(_warmup_time_us, timing)
22
23
  case format
23
24
  when :human
24
- $stdout.printf "%s i/100ms\n", Helpers.scale(timing)
25
+ @out.printf "%s i/100ms\n", Helpers.scale(timing)
25
26
  else
26
- $stdout.printf "%10d i/100ms\n", timing
27
+ @out.printf "%10d i/100ms\n", timing
27
28
  end
28
29
  end
29
30
 
30
31
  alias_method :running, :warming
31
32
 
32
33
  def add_report(item, caller)
33
- $stdout.puts " #{item.body}"
34
+ @out.puts " #{item.body}"
34
35
  @last_item = item
35
36
  end
36
37
 
37
38
  def footer
38
39
  return unless @last_item
39
40
  footer = @last_item.stats.footer
40
- $stdout.puts footer.rjust(40) if footer
41
+ @out.puts footer.rjust(40) if footer
41
42
  end
42
43
 
43
44
  private
@@ -53,11 +53,15 @@ module Benchmark
53
53
 
54
54
  # Silence output
55
55
  # @return [Boolean]
56
- attr_reader :quiet
56
+ def quiet
57
+ @out.quiet?
58
+ end
57
59
 
58
60
  # Suite
59
- # @return [Benchmark::IPS::NoopSuite]
60
- attr_reader :suite
61
+ # @return [Benchmark::IPS::MultiReport]
62
+ def suite
63
+ @out
64
+ end
61
65
 
62
66
  # Instantiate the Benchmark::IPS::Job.
63
67
  def initialize opts={}
@@ -81,7 +85,7 @@ module Benchmark
81
85
  @stats = :sd
82
86
  @confidence = 95
83
87
 
84
- self.quiet = false
88
+ @out = MultiReport.new(StreamReport.new)
85
89
  end
86
90
 
87
91
  # Job configuration options, set +@warmup+ and +@time+.
@@ -91,24 +95,23 @@ module Benchmark
91
95
  def config opts
92
96
  @warmup = opts[:warmup] if opts[:warmup]
93
97
  @time = opts[:time] if opts[:time]
94
- @suite = opts[:suite] if opts[:suite]
95
98
  @iterations = opts[:iterations] if opts[:iterations]
96
99
  @stats = opts[:stats] if opts[:stats]
97
100
  @confidence = opts[:confidence] if opts[:confidence]
98
101
  self.quiet = opts[:quiet] if opts.key?(:quiet)
99
- self.suite = opts[:suite]
102
+ self.suite = opts[:suite] if opts[:suite]
100
103
  end
101
104
 
102
105
  def quiet=(val)
103
- @stdout = reporter(quiet: val)
106
+ if val # remove instances of StreamReport
107
+ @out.quiet!
108
+ else # ensure there is an instance of StreamReport
109
+ @out << StreamReport.new if @out.quiet?
110
+ end
104
111
  end
105
112
 
106
113
  def suite=(suite)
107
- @suite = suite || Benchmark::IPS::NoopSuite.new
108
- end
109
-
110
- def reporter(quiet:)
111
- quiet ? NoopReport.new : StdoutReport.new
114
+ @out << suite
112
115
  end
113
116
 
114
117
  # Return true if job needs to be compared.
@@ -245,19 +248,19 @@ module Benchmark
245
248
 
246
249
  def run
247
250
  if @warmup && @warmup != 0 then
248
- @stdout.start_warming
251
+ @out.start_warming
249
252
  @iterations.times do
250
253
  run_warmup
251
254
  end
252
255
  end
253
256
 
254
- @stdout.start_running
257
+ @out.start_running
255
258
 
256
259
  @iterations.times do |n|
257
260
  run_benchmark
258
261
  end
259
262
 
260
- @stdout.footer
263
+ @out.footer
261
264
  end
262
265
 
263
266
  # Run warmup.
@@ -265,8 +268,7 @@ module Benchmark
265
268
  @list.each do |item|
266
269
  next if run_single? && @held_results && @held_results.key?(item.label)
267
270
 
268
- @suite.warming item.label, @warmup
269
- @stdout.warming item.label, @warmup
271
+ @out.warming item.label, @warmup
270
272
 
271
273
  Timing.clean_env
272
274
 
@@ -300,8 +302,7 @@ module Benchmark
300
302
  item.call_times cycles
301
303
  end
302
304
 
303
- @stdout.warmup_stats warmup_time_us, @timing[item]
304
- @suite.warmup_stats warmup_time_us, @timing[item]
305
+ @out.warmup_stats warmup_time_us, @timing[item]
305
306
 
306
307
  break if run_single?
307
308
  end
@@ -312,8 +313,7 @@ module Benchmark
312
313
  @list.each do |item|
313
314
  next if run_single? && @held_results && @held_results.key?(item.label)
314
315
 
315
- @suite.running item.label, @time
316
- @stdout.running item.label, @time
316
+ @out.running item.label, @time
317
317
 
318
318
  Timing.clean_env
319
319
 
@@ -355,8 +355,7 @@ module Benchmark
355
355
  rep.show_total_time!
356
356
  end
357
357
 
358
- @stdout.add_report rep, caller(1).first
359
- @suite.add_report rep, caller(1).first
358
+ @out.add_report rep, caller(1).first
360
359
 
361
360
  break if run_single?
362
361
  end
data/lib/benchmark/ips.rb CHANGED
@@ -5,10 +5,9 @@ require 'benchmark/ips/stats/stats_metric'
5
5
  require 'benchmark/ips/stats/sd'
6
6
  require 'benchmark/ips/stats/bootstrap'
7
7
  require 'benchmark/ips/report'
8
- require 'benchmark/ips/noop_suite'
9
8
  require 'benchmark/ips/job/entry'
10
- require 'benchmark/ips/job/stdout_report'
11
- require 'benchmark/ips/job/noop_report'
9
+ require 'benchmark/ips/job/stream_report'
10
+ require 'benchmark/ips/job/multi_report'
12
11
  require 'benchmark/ips/job'
13
12
 
14
13
  # Performance benchmarking library
@@ -18,10 +17,10 @@ module Benchmark
18
17
  module IPS
19
18
 
20
19
  # Benchmark-ips Gem version.
21
- VERSION = "2.11.0"
20
+ VERSION = "2.12.0"
22
21
 
23
22
  # CODENAME of current version.
24
- CODENAME = "We Do This Once A Year"
23
+ CODENAME = "Long Awaited"
25
24
 
26
25
  # Measure code in block, each code's benchmarked result will display in
27
26
  # iteration per second with standard deviation in given time.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark-ips
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix
@@ -59,9 +59,8 @@ files:
59
59
  - lib/benchmark/ips.rb
60
60
  - lib/benchmark/ips/job.rb
61
61
  - lib/benchmark/ips/job/entry.rb
62
- - lib/benchmark/ips/job/noop_report.rb
63
- - lib/benchmark/ips/job/stdout_report.rb
64
- - lib/benchmark/ips/noop_suite.rb
62
+ - lib/benchmark/ips/job/multi_report.rb
63
+ - lib/benchmark/ips/job/stream_report.rb
65
64
  - lib/benchmark/ips/report.rb
66
65
  - lib/benchmark/ips/share.rb
67
66
  - lib/benchmark/ips/stats/bootstrap.rb
@@ -1,27 +0,0 @@
1
- module Benchmark
2
- module IPS
3
- class Job
4
- class NoopReport
5
- def start_warming
6
- end
7
-
8
- def start_running
9
- end
10
-
11
- def footer
12
- end
13
-
14
- def warming(a, b)
15
- end
16
-
17
- def warmup_stats(a, b)
18
- end
19
-
20
- def add_report(a, b)
21
- end
22
-
23
- alias_method :running, :warming
24
- end
25
- end
26
- end
27
- end
@@ -1,25 +0,0 @@
1
- module Benchmark
2
- module IPS
3
- class NoopSuite
4
- def start_warming
5
- end
6
-
7
- def start_running
8
- end
9
-
10
- def footer
11
- end
12
-
13
- def warming(a, b)
14
- end
15
-
16
- def warmup_stats(a, b)
17
- end
18
-
19
- def add_report(a, b)
20
- end
21
-
22
- alias_method :running, :warming
23
- end
24
- end
25
- end