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, ips, ips_sd, cycles) ⇒ Entry

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

Parameters:

  • label (#to_s)

    Label of entry.

  • us (Integer)

    Measured time in microsecond.

  • iters (Integer)

    Iterations.

  • ips (Float)

    Iterations per second.

  • ips_sd (Float)

    Standard deviation of iterations per second.

  • cycles (Integer)

    Number of Cycles.



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

#ipsFloat (readonly)

Iterations per second.

Returns:

  • (Float)

    number of iterations per second.



43
44
45
# File 'lib/benchmark/ips/report.rb', line 43

def ips
  @ips
end

#ips_sdFloat (readonly)

Standard deviation of iteration per second.

Returns:

  • (Float)

    standard deviation of iteration per second.



47
48
49
# File 'lib/benchmark/ips/report.rb', line 47

def ips_sd
  @ips_sd
end

#iterationsInteger (readonly)

Number of Iterations.

Returns:

  • (Integer)

    number of iterations.



39
40
41
# File 'lib/benchmark/ips/report.rb', line 39

def iterations
  @iterations
end

#labelString (readonly)

Label of entry.

Returns:

  • (String)

    the label of entry.



31
32
33
# File 'lib/benchmark/ips/report.rb', line 31

def label
  @label
end

#measurement_cycleInteger (readonly)

Number of Cycles.

Returns:

  • (Integer)

    number of cycles.



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

def measurement_cycle
  @measurement_cycle
end

#microsecondsInteger (readonly)

Measured time in microsecond.

Returns:

  • (Integer)

    number of microseconds.



35
36
37
# File 'lib/benchmark/ips/report.rb', line 35

def microseconds
  @microseconds
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.



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

#displayObject

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

#headerString

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

Returns:

  • (String)

    Right justified header (+@label+).



102
103
104
# File 'lib/benchmark/ips/report.rb', line 102

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

#secondsFloat Also known as: runtime

Return entry's microseconds in seconds.

Returns:

  • (Float)

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

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

Returns:

  • (Float)

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

Return string repesentation of Entry object.

Returns:

  • (String)

    Header and body.



108
109
110
# File 'lib/benchmark/ips/report.rb', line 108

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