Class: Benchmark::ColoredReport

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = 0, format = nil) ⇒ ColoredReport

Returns a new instance of ColoredReport.



5
6
7
# File 'lib/penchmark/benchmark.rb', line 5

def initialize(width = 0, format = nil)
  @width, @format, @list = width, format, []
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



25
26
27
# File 'lib/penchmark/benchmark.rb', line 25

def list
  @list
end

Instance Method Details

#item(label = "", min_value = 0.0, max_value = 1.1, *format, &blk) ⇒ Object Also known as: report

:yield:



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/penchmark/benchmark.rb', line 9

def item(label = "", min_value = 0.0, max_value = 1.1, *format, &blk) # :yield:
  @list << res = Benchmark.measure(label, &blk)
  real_value = res.real

  if real_value > min_value and real_value < max_value
    print label.to_s.ljust(@width).green
    print res.format(@format, *format).green
  else
    print label.to_s.ljust(@width).red
    print res.format(@format, *format).red
  end
  res
end