Class: Benchmarkable::BenchmarkReport

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

Defined Under Namespace

Classes: Data

Instance Method Summary collapse

Instance Method Details

#add_entry_for(description) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/benchmarkable.rb', line 76

def add_entry_for(description)
  result = nil
  call_stack << []
  data = Data.new(description) do
    result = yield
  end
  call_stack.pop.each {|nested_call_data| data << nested_call_data }
  call_stack.last << data
  result
end

#entries(options = {}) ⇒ Object



96
97
98
99
100
# File 'lib/benchmarkable.rb', line 96

def entries(options = {})
  starting_context = options[:starting_context].to_a || []
  nesting_limit = options[:nesting_limit] == :none ? call_stack.first.collect {|data| data.nested_levels }.max : options[:nesting_limit] || 0
  call_stack.first.collect {|data| data.to_entry(starting_context, nesting_limit) }.flatten
end

#to_csv(options = {}) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/benchmarkable.rb', line 87

def to_csv(options = {})
  csv_options = {:force_quotes => true, :encoding => 'U'}.merge(options.delete(:csv_options) || {})
  FasterCSV.generate(csv_options) do |csv|
    entries(options).each do |entry|
      csv << [entry[:timestamp].to_s, entry[:context], entry[:execution_time].real].flatten
    end
  end
end