Module: Benchmark

Defined in:
lib/penchmark/benchmark.rb

Defined Under Namespace

Classes: ColoredReport

Class Method Summary collapse

Class Method Details

.pbm(label_width = 0, *labels, &blk) ⇒ Object



44
45
46
# File 'lib/penchmark/benchmark.rb', line 44

def self.pbm(label_width = 0, *labels, &blk)
  penchmark(CAPTION, label_width, FORMAT, *labels, &blk)
end

.penchmark(caption = '', label_width = nil, format = nil, *labels) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/penchmark/benchmark.rb', line 28

def self.penchmark(caption = '', label_width = nil, format = nil, *labels)

  label_width ||= 0
  label_width += 1
  format ||= FORMAT
  print "#{' '*label_width + caption}".blue unless caption.empty?
  report = ColoredReport.new(label_width, format)
  results = yield(report)
  print "#{'-'*label_width}\n".yellow
  Array === results and results.grep(Tms).each { |t|
    print((labels.shift || t.label || "").ljust(label_width).yellow, t.format(format.yellow))
  }
  report.list
end