Class: Benchmark::IPS::Report::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/ips/report.rb

Overview

Represents benchmarking code data for Report.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, us, iters, stats, cycles) ⇒ Entry

Instantiate the Benchmark::IPS::Report::Entry.

Parameters:

  • label (#to_s)

    Label of entry.

  • us (Integer)

    Measured time in microsecond.

  • iters (Integer)

    Iterations.

  • stats (Object)

    Statistics.

  • cycles (Integer)

    Number of Cycles.



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

#iterationsInteger (readonly)

Number of Iterations.

Returns:

  • (Integer)

    number of iterations.



37
38
39
# File 'lib/benchmark/ips/report.rb', line 37

def iterations
  @iterations
end

#labelString (readonly)

Label of entry.

Returns:

  • (String)

    the label of entry.



29
30
31
# File 'lib/benchmark/ips/report.rb', line 29

def label
  @label
end

#measurement_cycleInteger (readonly)

Number of Cycles.

Returns:

  • (Integer)

    number of cycles.



61
62
63
# File 'lib/benchmark/ips/report.rb', line 61

def measurement_cycle
  @measurement_cycle
end

#microsecondsInteger (readonly)

Measured time in microsecond.

Returns:

  • (Integer)

    number of microseconds.



33
34
35
# File 'lib/benchmark/ips/report.rb', line 33

def microseconds
  @microseconds
end

#statsObject (readonly)

Statistical summary of samples.

Returns:

  • (Object)

    statisical summary.



41
42
43
# File 'lib/benchmark/ips/report.rb', line 41

def stats
  @stats
end

Instance Method Details

#bodyString

Return Entry body text with left padding. Body text contains information of iteration per second with percentage of standard deviation, iterations in runtime.

Returns:

  • (String)

    Left justified body.



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.options[: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

#displayObject

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_percentageFloat

Return entry’s standard deviation of iteration per second in percentage.

Returns:

  • (Float)

    @ips_sd in percentage.



78
79
80
# File 'lib/benchmark/ips/report.rb', line 78

def error_percentage
  @stats.error_percentage
end

#headerString

Return header with padding if @label is < length of 20.

Returns:

  • (String)

    Right justified header (+@label+).



114
115
116
# File 'lib/benchmark/ips/report.rb', line 114

def header
  @label.to_s.rjust(20)
end

#ipsFloat

LEGACY: Iterations per second.

Returns:

  • (Float)

    number of iterations per second.



45
46
47
# File 'lib/benchmark/ips/report.rb', line 45

def ips
  @stats.central_tendency
end

#ips_sdFloat

LEGACY: Standard deviation of iteration per second.

Returns:

  • (Float)

    standard deviation of iteration per second.



51
52
53
# File 'lib/benchmark/ips/report.rb', line 51

def ips_sd
  @stats.error
end

#samplesObject



55
56
57
# File 'lib/benchmark/ips/report.rb', line 55

def samples
  @stats.samples
end

#secondsFloat Also known as: runtime

Return entry’s microseconds in seconds.

Returns:

  • (Float)

    @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_sString

Return string representation of Entry object.

Returns:

  • (String)

    Header and body.



120
121
122
# File 'lib/benchmark/ips/report.rb', line 120

def to_s
  "#{header} #{body}"
end