Module: Chap::Benchmarking

Included in:
Hook, Runner, Strategy::Checkout, Strategy::Copy
Defined in:
lib/chap/benchmarking.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
# File 'lib/chap/benchmarking.rb', line 5

def self.included(base)
  @@benchmarks = []
  base.extend(ClassMethods)
end

Instance Method Details

#benchmarksObject



50
51
52
# File 'lib/chap/benchmarking.rb', line 50

def benchmarks
  @@benchmarks
end

#report_benchmarksObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chap/benchmarking.rb', line 54

def report_benchmarks
  return if benchmarks.empty?
  report = []
  report << "Benchmark Report:"

  max = benchmarks.collect{|x| x[0]}.max_by{|a| a.length}.length
  report_block = lambda do |data|
    name,took = data
    mins = '%d' % (took / 60.0)
    secs = '%d' % (took % 60.0)
    report << "  %-#{max}s : %2s mins and %2s secs" % [name,mins,secs]
  end

  report << "Ordered by slowest:"
  benchmarks.sort_by {|x| x[1]}.reverse.each(&report_block)

  report.each do |line|
    log(line) unless options[:quiet]
  end
end

#shorten_name(string) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/chap/benchmarking.rb', line 40

def shorten_name(string)
  if string.length >= 80
    preprend = string[0,20]
    append = string[-55..-1]
    preprend + ' ... ' + append
  else 
    string
  end
end