Class: Benchmark::Perf::CPUResult

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/perf/cpu_result.rb

Constant Summary collapse

NO_VALUE =

Indicate no value

Module.new

Instance Method Summary collapse

Constructor Details

#initializeCPUResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create storage for ips results



14
15
16
17
18
19
# File 'lib/benchmark/perf/cpu_result.rb', line 14

def initialize
  @avg = NO_VALUE
  @stdev = NO_VALUE
  @dt = NO_VALUE
  @measurements = []
end

Instance Method Details

#add(time_s) ⇒ Object Also known as: <<

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
# File 'lib/benchmark/perf/cpu_result.rb', line 22

def add(time_s)
  @measurements << time_s
  @avg = NO_VALUE
  @stdev = NO_VALUE
  @dt = NO_VALUE
end

#avgInteger

Average ips

Returns:

  • (Integer)


35
36
37
38
39
# File 'lib/benchmark/perf/cpu_result.rb', line 35

def avg
  return @avg unless @avg == NO_VALUE

  @avg = Stats.average(@measurements)
end

#dtFloat Also known as: elapsed_time

The time elapsed

Returns:

  • (Float)


57
58
59
60
61
# File 'lib/benchmark/perf/cpu_result.rb', line 57

def dt
  return @dt unless @dt == NO_VALUE

  @dt = @measurements.reduce(0, :+)
end

#inspectObject

A string representation of this instance



73
74
75
# File 'lib/benchmark/perf/cpu_result.rb', line 73

def inspect
  "#<#{self.class.name} @avg=#{avg} @stdev=#{stdev} @dt=#{dt}>"
end

#stdevInteger

The ips standard deviation

Returns:

  • (Integer)


46
47
48
49
50
# File 'lib/benchmark/perf/cpu_result.rb', line 46

def stdev
  return @stdev unless @stdev == NO_VALUE

  @stdev = Stats.stdev(@measurements)
end

#to_aObject Also known as: to_ary



65
66
67
# File 'lib/benchmark/perf/cpu_result.rb', line 65

def to_a
  [avg, stdev, dt]
end