Class: Benchmark::Perf::IPSResult

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

Constant Summary collapse

NO_VALUE =

Indicate no value

Module.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIPSResult

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



18
19
20
21
22
23
24
25
# File 'lib/benchmark/perf/ips_result.rb', line 18

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

Instance Attribute Details

#ipsObject (readonly)

Returns the value of attribute ips.



11
12
13
# File 'lib/benchmark/perf/ips_result.rb', line 11

def ips
  @ips
end

#iterObject (readonly)

Returns the value of attribute iter.



13
14
15
# File 'lib/benchmark/perf/ips_result.rb', line 13

def iter
  @iter
end

Instance Method Details

#add(time_s, cycles_in_100ms) ⇒ Object

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.



28
29
30
31
32
33
34
35
# File 'lib/benchmark/perf/ips_result.rb', line 28

def add(time_s, cycles_in_100ms)
  @measurements << time_s
  @iter += cycles_in_100ms
  @ips << cycles_in_100ms.to_f / time_s.to_f
  @avg = NO_VALUE
  @stdev = NO_VALUE
  @dt = NO_VALUE
end

#avgInteger

Average ips

Returns:

  • (Integer)


42
43
44
45
46
# File 'lib/benchmark/perf/ips_result.rb', line 42

def avg
  return @avg unless @avg == NO_VALUE

  @avg = Stats.average(ips).round
end

#dtFloat Also known as: elapsed_time

The time elapsed

Returns:

  • (Float)


64
65
66
67
68
# File 'lib/benchmark/perf/ips_result.rb', line 64

def dt
  return @dt unless @dt == NO_VALUE

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

#inspectObject

A string representation of this instance



80
81
82
# File 'lib/benchmark/perf/ips_result.rb', line 80

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

#stdevInteger

The ips standard deviation

Returns:

  • (Integer)


53
54
55
56
57
# File 'lib/benchmark/perf/ips_result.rb', line 53

def stdev
  return @stdev unless @stdev == NO_VALUE

  @stdev = Stats.stdev(ips).round
end

#to_aObject Also known as: to_ary



72
73
74
# File 'lib/benchmark/perf/ips_result.rb', line 72

def to_a
  [avg, stdev, iter, dt]
end