benchmark-ips 2.9.3 → 2.10.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: cc5ffa1a7718a0e1228ff02e0473d0ca7596a0e2ed2f1837f8e7d2b6671fee80
4
- data.tar.gz: 59f55a6921d0e0c2f85b37724fd1e73175bb45c83ab929476d1eecf6e20fec68
3
+ metadata.gz: 0516f3e1e35f43a8fe32a6f32357aa124478ba54228ffe57d928cfc1231851bc
4
+ data.tar.gz: d62da6a6c1d2696b7667bd125ffe6bb2c33b3d61da5c393e729d7ca8a3d70ee7
5
5
  SHA512:
6
- metadata.gz: be49c48e45aea4ca566cfb52d8e6b50eefb3e367db9733aea730af7e1191d78171c002dcb5c0308a7fe695764d5c028fcf9b088a7edd55227b7097f4b8d4a1da
7
- data.tar.gz: 6c240a8f140c33a7164352be7d60a00e20aca04a91f5727d9753e6fd0aaac58e9a2bed6a3afb72ab290386dbe5bde7757e7206704e9806f53001d40091b4e346
6
+ metadata.gz: b644d293980f1ac9e3158abbe4f2c9d44d23185878edb9cb3861f3ca4f6837d557f89f8eb19bfcc42a45f53f3d112f2fe3ab22fc85a9633ede7e678b5fb90336
7
+ data.tar.gz: afe9972cdecdb2f42d4946afbac3d02cb3ead3a3d47a804960026ea77487cf885f6ddd7368edb13c522ee11e251599bf953d3d9a8172411c10e7259f7e9352b2
data/History.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 2.10.0 / 2022-02-17
2
+
3
+ * Feature
4
+ * Adds :order option to compare, with new `:baseline` order which compares all
5
+ variations against the first option benchmarked.
6
+
1
7
  ### 2.9.3 / 2022-01-25
2
8
 
3
9
  * Bug fix
@@ -26,31 +26,67 @@ module Benchmark
26
26
  # Reduce using to_proc: 247295.4 i/s - 1.13x slower
27
27
  #
28
28
  # Besides regular Calculating report, this will also indicates which one is slower.
29
+ #
30
+ # +x.compare!+ also takes an +order: :baseline+ option.
31
+ #
32
+ # Example:
33
+ # > Benchmark.ips do |x|
34
+ # x.report('Reduce using block') { [*1..10].reduce { |sum, n| sum + n } }
35
+ # x.report('Reduce using tag') { [*1..10].reduce(:+) }
36
+ # x.report('Reduce using to_proc') { [*1..10].reduce(&:+) }
37
+ # x.compare!(order: :baseline)
38
+ # end
39
+ #
40
+ # Calculating -------------------------------------
41
+ # Reduce using block 886.202k (± 2.2%) i/s - 4.521M in 5.103774s
42
+ # Reduce using tag 1.821M (± 1.6%) i/s - 9.111M in 5.004183s
43
+ # Reduce using to_proc 895.948k (± 1.6%) i/s - 4.528M in 5.055368s
44
+ #
45
+ # Comparison:
46
+ # Reduce using block: 886202.5 i/s
47
+ # Reduce using tag: 1821055.0 i/s - 2.05x (± 0.00) faster
48
+ # Reduce using to_proc: 895948.1 i/s - same-ish: difference falls within error
49
+ #
50
+ # The first report is considered the baseline against which other reports are compared.
29
51
  module Compare
30
52
 
31
53
  # Compare between reports, prints out facts of each report:
32
54
  # runtime, comparative speed difference.
33
55
  # @param entries [Array<Report::Entry>] Reports to compare.
34
- def compare(*entries)
56
+ def compare(*entries, order: :fastest)
35
57
  return if entries.size < 2
36
58
 
37
- sorted = entries.sort_by{ |e| e.stats.central_tendency }.reverse
38
-
39
- best = sorted.shift
59
+ case order
60
+ when :baseline
61
+ baseline = entries.shift
62
+ sorted = entries.sort_by{ |e| e.stats.central_tendency }.reverse
63
+ when :fastest
64
+ sorted = entries.sort_by{ |e| e.stats.central_tendency }.reverse
65
+ baseline = sorted.shift
66
+ else
67
+ raise ArgumentError, "Unknwon order: #{order.inspect}"
68
+ end
40
69
 
41
70
  $stdout.puts "\nComparison:"
42
71
 
43
- $stdout.printf "%20s: %10.1f i/s\n", best.label.to_s, best.stats.central_tendency
72
+ $stdout.printf "%20s: %10.1f i/s\n", baseline.label.to_s, baseline.stats.central_tendency
44
73
 
45
74
  sorted.each do |report|
46
75
  name = report.label.to_s
47
76
 
48
77
  $stdout.printf "%20s: %10.1f i/s - ", name, report.stats.central_tendency
49
78
 
50
- if report.stats.overlaps?(best.stats)
79
+ if report.stats.overlaps?(baseline.stats)
51
80
  $stdout.print "same-ish: difference falls within error"
81
+ elsif report.stats.central_tendency > baseline.stats.central_tendency
82
+ speedup, error = report.stats.speedup(baseline.stats)
83
+ $stdout.printf "%.2fx ", speedup
84
+ if error
85
+ $stdout.printf " (± %.2f)", error
86
+ end
87
+ $stdout.print " faster"
52
88
  else
53
- slowdown, error = report.stats.slowdown(best.stats)
89
+ slowdown, error = report.stats.slowdown(baseline.stats)
54
90
  $stdout.printf "%.2fx ", slowdown
55
91
  if error
56
92
  $stdout.printf " (± %.2f)", error
@@ -61,7 +97,7 @@ module Benchmark
61
97
  $stdout.puts
62
98
  end
63
99
 
64
- footer = best.stats.footer
100
+ footer = baseline.stats.footer
65
101
  $stdout.puts footer.rjust(40) if footer
66
102
 
67
103
  $stdout.puts
@@ -65,6 +65,7 @@ module Benchmark
65
65
  @run_single = false
66
66
  @json_path = false
67
67
  @compare = false
68
+ @compare_order = :fastest
68
69
  @held_path = nil
69
70
  @held_results = nil
70
71
 
@@ -117,8 +118,9 @@ module Benchmark
117
118
  end
118
119
 
119
120
  # Run comparison utility.
120
- def compare!
121
+ def compare!(order: :fastest)
121
122
  @compare = true
123
+ @compare_order = order
122
124
  end
123
125
 
124
126
  # Return true if results are held while multiple Ruby invocations
@@ -373,7 +375,7 @@ module Benchmark
373
375
 
374
376
  # Run comparison of entries in +@full_report+.
375
377
  def run_comparison
376
- @full_report.run_comparison if compare?
378
+ @full_report.run_comparison(@compare_order) if compare?
377
379
  end
378
380
 
379
381
  # Generate json from +@full_report+.
@@ -176,8 +176,8 @@ module Benchmark
176
176
  end
177
177
 
178
178
  # Run comparison of entries.
179
- def run_comparison
180
- Benchmark.compare(*@entries)
179
+ def run_comparison(order)
180
+ Benchmark.compare(*@entries, order: order)
181
181
  end
182
182
 
183
183
  # Generate json from Report#data to given path.
@@ -33,6 +33,10 @@ module Benchmark
33
33
  [slowdown, error]
34
34
  end
35
35
 
36
+ def speedup(baseline)
37
+ baseline.slowdown(self)
38
+ end
39
+
36
40
  def footer
37
41
  "with #{(@confidence.to_f * 100).round(1)}% confidence"
38
42
  end
@@ -30,6 +30,10 @@ module Benchmark
30
30
  end
31
31
  end
32
32
 
33
+ def speedup(baseline)
34
+ baseline.slowdown(self)
35
+ end
36
+
33
37
  def footer
34
38
  nil
35
39
  end
data/lib/benchmark/ips.rb CHANGED
@@ -18,10 +18,10 @@ module Benchmark
18
18
  module IPS
19
19
 
20
20
  # Benchmark-ips Gem version.
21
- VERSION = "2.9.3"
21
+ VERSION = "2.10.0"
22
22
 
23
23
  # CODENAME of current version.
24
- CODENAME = "Sleepy Sasquatch"
24
+ CODENAME = "Watashi Wa Genki"
25
25
 
26
26
  # Measure code in block, each code's benchmarked result will display in
27
27
  # 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.9.3
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix