Class: Benchmark::ColoredReport
- Inherits:
-
Object
- Object
- Benchmark::ColoredReport
- Defined in:
- lib/penchmark/benchmark.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Instance Method Summary collapse
-
#initialize(width = 0, format = nil) ⇒ ColoredReport
constructor
A new instance of ColoredReport.
-
#item(label = "", min_value = 0.0, max_value = 1.1, *format, &blk) ⇒ Object
(also: #report)
:yield:.
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
#list ⇒ Object (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 |