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 +4 -4
- data/README.md +1 -1
- data/lib/benchmark/compare.rb +4 -2
- data/lib/benchmark/ips/job/stream_report.rb +4 -16
- data/lib/benchmark/ips/job.rb +19 -9
- data/lib/benchmark/ips/report.rb +9 -1
- data/lib/benchmark/ips/share.rb +1 -1
- data/lib/benchmark/ips/stats/sd.rb +2 -2
- data/lib/benchmark/ips.rb +2 -2
- data/lib/benchmark/timing.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 941e6893612b6307694098b25ebe3cc688dac27020c98cf76d603ead0bd72299
|
|
4
|
+
data.tar.gz: 622715bcc49a8e11c1c6285b35745b9115417e1055b8dc394ca6f5ba07186b66
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
[](http://badge.fury.io/rb/benchmark-ips)
|
|
7
|
-
[](https://github.com/evanphx/benchmark-ips/actions/workflows/ci.yml)
|
|
8
8
|
[](http://inch-ci.org/github/evanphx/benchmark-ips)
|
|
9
9
|
|
|
10
10
|
* https://github.com/evanphx/benchmark-ips
|
data/lib/benchmark/compare.rb
CHANGED
|
@@ -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 "
|
|
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 "
|
|
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(
|
|
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
|
data/lib/benchmark/ips/job.rb
CHANGED
|
@@ -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
|
-
|
|
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 >=
|
|
300
|
+
break if cycles >= MAX_ITERATIONS
|
|
293
301
|
cycles *= 2
|
|
294
302
|
end while Timing.now + warmup_time_us * 2 < target
|
|
295
303
|
|
|
296
|
-
|
|
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
|
data/lib/benchmark/ips/report.rb
CHANGED
|
@@ -90,7 +90,15 @@ module Benchmark
|
|
|
90
90
|
|
|
91
91
|
case Benchmark::IPS.options[:format]
|
|
92
92
|
when :human
|
|
93
|
-
|
|
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
|
data/lib/benchmark/ips/share.rb
CHANGED
|
@@ -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.
|
|
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.
|
|
23
|
+
VERSION = "2.15.0"
|
|
24
24
|
|
|
25
25
|
# CODENAME of current version.
|
|
26
|
-
CODENAME = "
|
|
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.
|
data/lib/benchmark/timing.rb
CHANGED
|
@@ -4,9 +4,9 @@ module Benchmark
|
|
|
4
4
|
# Microseconds per second.
|
|
5
5
|
MICROSECONDS_PER_SECOND = 1_000_000
|
|
6
6
|
|
|
7
|
-
# Calculate
|
|
7
|
+
# Calculate arithmetic mean of given numbers.
|
|
8
8
|
# @param [Array] samples Samples to calculate mean.
|
|
9
|
-
# @return [Float] Mean of given
|
|
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.
|
|
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.
|
|
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: []
|