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
-
#ips ⇒ Float
readonly
Iterations per second.
-
#ips_sd ⇒ Float
readonly
Standard deviation of iteration per second.
-
#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.
Instance Method Summary collapse
-
#body ⇒ String
Return Entry body text with left padding.
-
#display ⇒ Object
Print entry to current standard output ($stdout).
-
#header ⇒ String
Return header with padding if @label is < length of 20.
-
#initialize(label, us, iters, ips, ips_sd, cycles) ⇒ Entry
constructor
Instantiate the Benchmark::IPS::Report::Entry.
-
#seconds ⇒ Float
(also: #runtime)
Return entry’s microseconds in seconds.
-
#show_total_time! ⇒ Object
Control if the total time the job took is reported.
-
#stddev_percentage ⇒ Float
Return entry’s standard deviation of iteration per second in percentage.
-
#to_s ⇒ String
Return string repesentation of Entry object.
Constructor Details
#initialize(label, us, iters, ips, ips_sd, cycles) ⇒ Entry
Instantiate the Benchmark::IPS::Report::Entry.
19 20 21 22 23 24 25 26 27 |
# File 'lib/benchmark/ips/report.rb', line 19 def initialize(label, us, iters, ips, ips_sd, cycles) @label = label @microseconds = us @iterations = iters @ips = ips @ips_sd = ips_sd @measurement_cycle = cycles @show_total_time = false end |
Instance Attribute Details
#ips ⇒ Float (readonly)
Iterations per second.
43 44 45 |
# File 'lib/benchmark/ips/report.rb', line 43 def ips @ips end |
#ips_sd ⇒ Float (readonly)
Standard deviation of iteration per second.
47 48 49 |
# File 'lib/benchmark/ips/report.rb', line 47 def ips_sd @ips_sd end |
#iterations ⇒ Integer (readonly)
Number of Iterations.
39 40 41 |
# File 'lib/benchmark/ips/report.rb', line 39 def iterations @iterations end |
#label ⇒ String (readonly)
Label of entry.
31 32 33 |
# File 'lib/benchmark/ips/report.rb', line 31 def label @label end |
#measurement_cycle ⇒ Integer (readonly)
Number of Cycles.
51 52 53 |
# File 'lib/benchmark/ips/report.rb', line 51 def measurement_cycle @measurement_cycle end |
#microseconds ⇒ Integer (readonly)
Measured time in microsecond.
35 36 37 |
# File 'lib/benchmark/ips/report.rb', line 35 def microseconds @microseconds 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.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/benchmark/ips/report.rb', line 78 def body case Benchmark::IPS.[:format] when :human left = "%s (±%4.1f%%) i/s" % [Helpers.scale(ips), stddev_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" % [ips, stddev_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).
113 114 115 |
# File 'lib/benchmark/ips/report.rb', line 113 def display $stdout.puts to_s end |
#header ⇒ String
Return header with padding if @label is < length of 20.
102 103 104 |
# File 'lib/benchmark/ips/report.rb', line 102 def header @label.to_s.rjust(20) end |
#seconds ⇒ Float Also known as: runtime
Return entry’s microseconds in seconds.
62 63 64 |
# File 'lib/benchmark/ips/report.rb', line 62 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.
56 57 58 |
# File 'lib/benchmark/ips/report.rb', line 56 def show_total_time! @show_total_time = true end |
#stddev_percentage ⇒ Float
Return entry’s standard deviation of iteration per second in percentage.
68 69 70 |
# File 'lib/benchmark/ips/report.rb', line 68 def stddev_percentage 100.0 * (@ips_sd.to_f / @ips.to_f) end |
#to_s ⇒ String
Return string repesentation of Entry object.
108 109 110 |
# File 'lib/benchmark/ips/report.rb', line 108 def to_s "#{header} #{body}" end |