benchmark-ips 2.14.0 → 2.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaebdee644671b1a757ded5e4868e1035718834832d2cfec8eb4460a3fa33171
4
- data.tar.gz: a7349d06bb190b2ea9b7c06caf8da4ba26a48b00e550ca8a71ed1fe22ddff290
3
+ metadata.gz: 941e6893612b6307694098b25ebe3cc688dac27020c98cf76d603ead0bd72299
4
+ data.tar.gz: 622715bcc49a8e11c1c6285b35745b9115417e1055b8dc394ca6f5ba07186b66
5
5
  SHA512:
6
- metadata.gz: 5b2cef3b3b852b48eb8cdbaa1b51b728edb0760d77983d5408e81a44d9dfc280f257456a57d8a213155ca0752508c81282e243daf2cbb16d1a95bdaac1b4d211
7
- data.tar.gz: 509f946e113907d26745e24a07675684b6870189fcdc36128380b286e774bb03e46a4608b3852aa68e110a2c1e594436e727b9626111bebf1b1a4bdeea7f71f8
6
+ metadata.gz: b0e5c2205809523369329ea675f095dc62cefa330e6adb6005b12a6ff4f4d5cfd38ffc16fe819761e4ed10a2c41b1100af8304c3a038383d2377700436873bbb
7
+ data.tar.gz: 318217090715cb2a541606ef8ab91087aec9238ffa0d6b29d5b2b1eeebc2e5d0a725856b59ded62081f1135f2a8bb916c25a31d604c0824accaf67e46ecfab8f
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  * home :: https://github.com/evanphx/benchmark-ips
5
5
 
6
6
  [![Gem Version](https://badge.fury.io/rb/benchmark-ips.svg)](http://badge.fury.io/rb/benchmark-ips)
7
- [![Build Status](https://secure.travis-ci.org/evanphx/benchmark-ips.svg)](http://travis-ci.org/evanphx/benchmark-ips)
7
+ [![CI](https://github.com/evanphx/benchmark-ips/actions/workflows/ci.yml/badge.svg)](https://github.com/evanphx/benchmark-ips/actions/workflows/ci.yml)
8
8
  [![Inline docs](http://inch-ci.org/github/evanphx/benchmark-ips.svg)](http://inch-ci.org/github/evanphx/benchmark-ips)
9
9
 
10
10
  * https://github.com/evanphx/benchmark-ips
@@ -56,6 +56,8 @@ module Benchmark
56
56
  def compare(*entries, order: :fastest)
57
57
  return if entries.size < 2
58
58
 
59
+ max_width = entries.map { |e| e.label.to_s.size }.max
60
+
59
61
  case order
60
62
  when :baseline
61
63
  baseline = entries.shift
@@ -69,12 +71,12 @@ module Benchmark
69
71
 
70
72
  $stdout.puts "\nComparison:"
71
73
 
72
- $stdout.printf "%20s: %10.1f i/s\n", baseline.label.to_s, baseline.stats.central_tendency
74
+ $stdout.printf "%#{max_width}s: %10.1f i/s\n", baseline.label.to_s, baseline.stats.central_tendency
73
75
 
74
76
  sorted.each do |report|
75
77
  name = report.label.to_s
76
78
 
77
- $stdout.printf "%20s: %10.1f i/s - ", name, report.stats.central_tendency
79
+ $stdout.printf "%#{max_width}s: %10.1f i/s - ", name, report.stats.central_tendency
78
80
 
79
81
  if report.stats.overlaps?(baseline.stats)
80
82
  $stdout.print "same-ish: difference falls within error"
@@ -2,9 +2,10 @@ module Benchmark
2
2
  module IPS
3
3
  class Job
4
4
  class StreamReport
5
- def initialize(stream = $stdout)
5
+ def initialize(job, stream = $stdout)
6
6
  @last_item = nil
7
7
  @out = stream
8
+ @job = job
8
9
  end
9
10
 
10
11
  def start_warming
@@ -17,8 +18,9 @@ module Benchmark
17
18
  end
18
19
 
19
20
  def warming(label, _warmup)
20
- @out.print rjust(label)
21
+ @out.print label.to_s.rjust(@job.max_width)
21
22
  end
23
+ alias_method :running, :warming
22
24
 
23
25
  def warmup_stats(_warmup_time_us, timing)
24
26
  case format
@@ -29,8 +31,6 @@ module Benchmark
29
31
  end
30
32
  end
31
33
 
32
- alias_method :running, :warming
33
-
34
34
  def add_report(item, caller)
35
35
  @out.puts " #{item.body}"
36
36
  @last_item = item
@@ -48,18 +48,6 @@ module Benchmark
48
48
  def format
49
49
  Benchmark::IPS.options[:format]
50
50
  end
51
-
52
- # Add padding to label's right if label's length < 20,
53
- # Otherwise add a new line and 20 whitespaces.
54
- # @return [String] Right justified label.
55
- def rjust(label)
56
- label = label.to_s
57
- if label.size > 20
58
- "#{label}\n#{' ' * 20}"
59
- else
60
- label.rjust(20)
61
- end
62
- end
63
51
  end
64
52
  end
65
53
  end
@@ -9,7 +9,8 @@ module Benchmark
9
9
  # The percentage of the expected runtime to allow
10
10
  # before reporting a weird runtime
11
11
  MAX_TIME_SKEW = 0.05
12
- POW_2_30 = 1 << 30
12
+ # Keep iterations below this to avoid overflow to 64-bit long or Bignum
13
+ MAX_ITERATIONS = 1 << 30
13
14
 
14
15
  # Two-element arrays, consisting of label and block pairs.
15
16
  # @return [Array<Entry>] list of entries
@@ -51,6 +52,10 @@ module Benchmark
51
52
  # @return [Integer]
52
53
  attr_accessor :confidence
53
54
 
55
+ # The maximum label width
56
+ # @return [Integer]
57
+ attr_reader :max_width
58
+
54
59
  # Silence output
55
60
  # @return [Boolean]
56
61
  def quiet
@@ -72,6 +77,7 @@ module Benchmark
72
77
  @compare_order = :fastest
73
78
  @held_path = nil
74
79
  @held_results = nil
80
+ @max_width = 20 # automatically computed as entries are added
75
81
 
76
82
  @timing = Hash.new 1 # default to 1 in case warmup isn't run
77
83
  @full_report = Report.new
@@ -85,7 +91,7 @@ module Benchmark
85
91
  @stats = :sd
86
92
  @confidence = 95
87
93
 
88
- @out = MultiReport.new(StreamReport.new)
94
+ @out = MultiReport.new(StreamReport.new(self))
89
95
  end
90
96
 
91
97
  # Job configuration options, set +@warmup+ and +@time+.
@@ -106,7 +112,7 @@ module Benchmark
106
112
  if val # remove instances of StreamReport
107
113
  @out.quiet!
108
114
  else # ensure there is an instance of StreamReport
109
- @out << StreamReport.new if @out.quiet?
115
+ @out << StreamReport.new(self) if @out.quiet?
110
116
  end
111
117
  end
112
118
 
@@ -180,6 +186,8 @@ module Benchmark
180
186
  action = str || blk
181
187
  raise ArgumentError, "no block or string" unless action
182
188
 
189
+ @max_width = label.size if label.size > @max_width
190
+
183
191
  @list.push Entry.new(label, action)
184
192
  self
185
193
  end
@@ -219,7 +227,7 @@ module Benchmark
219
227
  JSON.load(IO.read(@held_path)).each do |result|
220
228
  @held_results[result['item']] = result
221
229
  create_report(result['item'], result['measured_us'], result['iter'],
222
- create_stats(result['samples']), result['cycles'])
230
+ create_stats(result['samples'], result['measured_us'], result['iter']), result['cycles'])
223
231
  end
224
232
  end
225
233
 
@@ -289,11 +297,13 @@ module Benchmark
289
297
 
290
298
  # If the number of cycles would go outside the 32-bit signed integers range
291
299
  # then exit the loop to avoid overflows and start the 100ms warmup runs
292
- break if cycles >= POW_2_30
300
+ break if cycles >= MAX_ITERATIONS
293
301
  cycles *= 2
294
302
  end while Timing.now + warmup_time_us * 2 < target
295
303
 
296
- cycles = cycles_per_100ms warmup_time_us, warmup_iter
304
+ per_100ms = cycles_per_100ms warmup_time_us, warmup_iter
305
+ # Not [per_100ms, MAX_ITERATIONS].min as that can promote the result to long
306
+ cycles = per_100ms > MAX_ITERATIONS ? MAX_ITERATIONS : per_100ms
297
307
  @timing[item] = cycles
298
308
 
299
309
  # Run for the remaining of warmup in a similar way as #run_benchmark.
@@ -349,7 +359,7 @@ module Benchmark
349
359
  iterations_per_sec cycles, time_us
350
360
  }
351
361
 
352
- rep = create_report(item.label, measured_us, iter, create_stats(samples), cycles)
362
+ rep = create_report(item.label, measured_us, iter, create_stats(samples, measured_us, iter), cycles)
353
363
 
354
364
  if (final_time - target).abs >= (@time.to_f * MAX_TIME_SKEW)
355
365
  rep.show_total_time!
@@ -361,10 +371,10 @@ module Benchmark
361
371
  end
362
372
  end
363
373
 
364
- def create_stats(samples)
374
+ def create_stats(samples, measured_us, iterations)
365
375
  case @stats
366
376
  when :sd
367
- Stats::SD.new(samples)
377
+ Stats::SD.new(samples, measured_us, iterations)
368
378
  when :bootstrap
369
379
  Stats::Bootstrap.new(samples, @confidence)
370
380
  else
@@ -90,7 +90,15 @@ module Benchmark
90
90
 
91
91
  case Benchmark::IPS.options[:format]
92
92
  when :human
93
- left = ("%s (±%4.1f%%) i/s" % [Helpers.scale(@stats.central_tendency), @stats.error_percentage]).ljust(20)
93
+ central_tendency = Helpers.scale(@stats.central_tendency)
94
+ error_percentage = @stats.error_percentage
95
+ left =
96
+ if error_percentage > 99.9
97
+ "%s (± Inf%%) i/s" % [central_tendency]
98
+ else
99
+ "%s (±%4.1f%%) i/s" % [central_tendency, @stats.error_percentage]
100
+ end.ljust(20)
101
+
94
102
  iters = Helpers.scale(@iterations)
95
103
 
96
104
  if @show_total_time
@@ -17,7 +17,7 @@ module Benchmark
17
17
  base = (ENV['SHARE_URL'] || DEFAULT_URL)
18
18
  url = URI(File.join(base, "reports"))
19
19
 
20
- req = Net::HTTP::Post.new(url)
20
+ req = Net::HTTP::Post.new(url, initheader = {'Content-Type' =>'application/json'})
21
21
 
22
22
  data = {
23
23
  "entries" => @report.data,
@@ -6,9 +6,9 @@ module Benchmark
6
6
  include StatsMetric
7
7
  attr_reader :error, :samples
8
8
 
9
- def initialize(samples)
9
+ def initialize(samples, measured_us, iterations)
10
10
  @samples = samples
11
- @mean = Timing.mean(samples)
11
+ @mean = Timing::MICROSECONDS_PER_SECOND * (iterations.to_f / measured_us)
12
12
  @error = Timing.stddev(samples, @mean).round
13
13
  end
14
14
 
data/lib/benchmark/ips.rb CHANGED
@@ -20,10 +20,10 @@ module Benchmark
20
20
  module IPS
21
21
 
22
22
  # Benchmark-ips Gem version.
23
- VERSION = "2.14.0"
23
+ VERSION = "2.15.0"
24
24
 
25
25
  # CODENAME of current version.
26
- CODENAME = "Akagi"
26
+ CODENAME = "Harmonic Nice"
27
27
 
28
28
  # Measure code in block, each code's benchmarked result will display in
29
29
  # iteration per second with standard deviation in given time.
@@ -4,9 +4,9 @@ module Benchmark
4
4
  # Microseconds per second.
5
5
  MICROSECONDS_PER_SECOND = 1_000_000
6
6
 
7
- # Calculate (arithmetic) mean of given samples.
7
+ # Calculate arithmetic mean of given numbers.
8
8
  # @param [Array] samples Samples to calculate mean.
9
- # @return [Float] Mean of given samples.
9
+ # @return [Float] Mean of given numbers.
10
10
  def self.mean(samples)
11
11
  sum = samples.inject(:+)
12
12
  sum / samples.size
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark-ips
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.0
4
+ version: 2.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-01-12 00:00:00.000000000 Z
@@ -72,7 +72,7 @@ homepage: https://github.com/evanphx/benchmark-ips
72
72
  licenses:
73
73
  - MIT
74
74
  metadata: {}
75
- post_install_message:
75
+ post_install_message:
76
76
  rdoc_options:
77
77
  - "--main"
78
78
  - README.md
@@ -89,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 3.0.3.1
93
- signing_key:
92
+ rubygems_version: 3.4.20
93
+ signing_key:
94
94
  specification_version: 4
95
95
  summary: A iterations per second enhancement to Benchmark.
96
96
  test_files: []