Class: Benchmark::IPS::Report::Entry
- Inherits:
-
Object
- Object
- Benchmark::IPS::Report::Entry
- Defined in:
- lib/benchmark/ips/report.rb
Overview
Represents benchmarking code data for Report.
Instance Attribute Summary collapse
-
#iterations ⇒ Integer
readonly
Number of Iterations.
-
#label ⇒ String
readonly
Label of entry.
-
#measurement_cycle ⇒ Integer
readonly
Number of Cycles.
-
#microseconds ⇒ Integer
readonly
Measured time in microsecond.
-
#stats ⇒ Object
readonly
Statistical summary of samples.
Instance Method Summary collapse
-
#body ⇒ String
Return Entry body text with left padding.
-
#display ⇒ Object
Print entry to current standard output ($stdout).
-
#error_percentage ⇒ Float
Return entry’s standard deviation of iteration per second in percentage.
-
#header ⇒ String
Return header with padding if @label is < length of 20.
-
#initialize(label, us, iters, stats, cycles) ⇒ Entry
constructor
Instantiate the Benchmark::IPS::Report::Entry.
-
#ips ⇒ Float
LEGACY: Iterations per second.
-
#ips_sd ⇒ Float
LEGACY: Standard deviation of iteration per second.
- #samples ⇒ Object
-
#seconds ⇒ Float
(also: #runtime)
Return entry’s microseconds in seconds.
-
#show_total_time! ⇒ Object
Control if the total time the job took is reported.
-
#to_s ⇒ String
Return string representation of Entry object.
Constructor Details
#initialize(label, us, iters, stats, cycles) ⇒ Entry
Instantiate the Benchmark::IPS::Report::Entry.
18 19 20 21 22 23 24 25 |
# File 'lib/benchmark/ips/report.rb', line 18 def initialize(label, us, iters, stats, cycles) @label = label @microseconds = us @iterations = iters @stats = stats @measurement_cycle = cycles @show_total_time = false end |
Instance Attribute Details
#iterations ⇒ Integer (readonly)
Number of Iterations.
37 38 39 |
# File 'lib/benchmark/ips/report.rb', line 37 def iterations @iterations end |
#label ⇒ String (readonly)
Label of entry.
29 30 31 |
# File 'lib/benchmark/ips/report.rb', line 29 def label @label end |
#measurement_cycle ⇒ Integer (readonly)
Number of Cycles.
61 62 63 |
# File 'lib/benchmark/ips/report.rb', line 61 def measurement_cycle @measurement_cycle end |
#microseconds ⇒ Integer (readonly)
Measured time in microsecond.
33 34 35 |
# File 'lib/benchmark/ips/report.rb', line 33 def microseconds @microseconds end |
#stats ⇒ Object (readonly)
Statistical summary of samples.
41 42 43 |
# File 'lib/benchmark/ips/report.rb', line 41 def stats @stats end |
Instance Method Details
#body ⇒ String
Return Entry body text with left padding. Body text contains information of iteration per second with percentage of standard deviation, iterations in runtime.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/benchmark/ips/report.rb', line 88 def body per_iter = (" (%s/i)" % Helpers.humanize_duration(1_000_000_000 / @stats.central_tendency)).rjust(15) case Benchmark::IPS.[:format] when :human left = ("%s (±%4.1f%%) i/s" % [Helpers.scale(@stats.central_tendency), @stats.error_percentage]).ljust(20) iters = Helpers.scale(@iterations) if @show_total_time left + per_iter + (" - %s in %10.6fs" % [iters, runtime]) else left + per_iter + (" - %s" % iters) end else left = ("%10.1f (±%.1f%%) i/s" % [@stats.central_tendency, @stats.error_percentage]).ljust(20) if @show_total_time left + per_iter + (" - %10d in %10.6fs" % [@iterations, runtime]) else left + per_iter + (" - %10d" % @iterations) end end end |
#display ⇒ Object
Print entry to current standard output ($stdout).
125 126 127 |
# File 'lib/benchmark/ips/report.rb', line 125 def display $stdout.puts to_s end |
#error_percentage ⇒ Float
Return entry’s standard deviation of iteration per second in percentage.
78 79 80 |
# File 'lib/benchmark/ips/report.rb', line 78 def error_percentage @stats.error_percentage end |
#header ⇒ String
Return header with padding if @label is < length of 20.
114 115 116 |
# File 'lib/benchmark/ips/report.rb', line 114 def header @label.to_s.rjust(20) end |
#ips ⇒ Float
LEGACY: Iterations per second.
45 46 47 |
# File 'lib/benchmark/ips/report.rb', line 45 def ips @stats.central_tendency end |
#ips_sd ⇒ Float
LEGACY: Standard deviation of iteration per second.
51 52 53 |
# File 'lib/benchmark/ips/report.rb', line 51 def ips_sd @stats.error end |
#samples ⇒ Object
55 56 57 |
# File 'lib/benchmark/ips/report.rb', line 55 def samples @stats.samples end |
#seconds ⇒ Float Also known as: runtime
Return entry’s microseconds in seconds.
72 73 74 |
# File 'lib/benchmark/ips/report.rb', line 72 def seconds @microseconds.to_f / 1_000_000.0 end |
#show_total_time! ⇒ Object
Control if the total time the job took is reported. Typically this value is not significant because it’s very close to the expected time, so it’s suppressed by default.
66 67 68 |
# File 'lib/benchmark/ips/report.rb', line 66 def show_total_time! @show_total_time = true end |
#to_s ⇒ String
Return string representation of Entry object.
120 121 122 |
# File 'lib/benchmark/ips/report.rb', line 120 def to_s "#{header} #{body}" end |