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.
-
#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 repesentation 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.
57 58 59 |
# File 'lib/benchmark/ips/report.rb', line 57 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.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/benchmark/ips/report.rb', line 84 def body case Benchmark::IPS.[:format] when :human left = "%s (±%4.1f%%) i/s" % [Helpers.scale(@stats.central_tendency), error_percentage] iters = Helpers.scale(@iterations) if @show_total_time left.ljust(20) + (" - %s in %10.6fs" % [iters, runtime]) else left.ljust(20) + (" - %s" % iters) end else left = "%10.1f (±%.1f%%) i/s" % [@stats.central_tendency, error_percentage] if @show_total_time left.ljust(20) + (" - %10d in %10.6fs" % [@iterations, runtime]) else left.ljust(20) + (" - %10d" % @iterations) end end end |
#display ⇒ Object
Print entry to current standard output ($stdout).
119 120 121 |
# File 'lib/benchmark/ips/report.rb', line 119 def display $stdout.puts to_s end |
#error_percentage ⇒ Float
Return entry’s standard deviation of iteration per second in percentage.
74 75 76 |
# File 'lib/benchmark/ips/report.rb', line 74 def error_percentage 100.0 * (@stats.error.to_f / @stats.central_tendency) end |
#header ⇒ String
Return header with padding if @label is < length of 20.
108 109 110 |
# File 'lib/benchmark/ips/report.rb', line 108 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 |
#seconds ⇒ Float Also known as: runtime
Return entry’s microseconds in seconds.
68 69 70 |
# File 'lib/benchmark/ips/report.rb', line 68 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 supressed by default.
62 63 64 |
# File 'lib/benchmark/ips/report.rb', line 62 def show_total_time! @show_total_time = true end |
#to_s ⇒ String
Return string repesentation of Entry object.
114 115 116 |
# File 'lib/benchmark/ips/report.rb', line 114 def to_s "#{header} #{body}" end |