Class: Benchmarkable::BenchmarkReport::Data

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

Instance Method Summary collapse

Constructor Details

#initialize(description) ⇒ Data

Returns a new instance of Data.



109
110
111
112
113
114
115
# File 'lib/benchmarkable.rb', line 109

def initialize(description)
  @description = description
  @timestamp = DateTime.now
  @overall_time = Benchmark.measure do
    yield
  end
end

Instance Method Details

#<<(data_for_nested_call) ⇒ Object



117
118
119
# File 'lib/benchmarkable.rb', line 117

def <<(data_for_nested_call)
  data_for_nested_calls << data_for_nested_call
end

#nested_levelsObject



130
131
132
133
# File 'lib/benchmarkable.rb', line 130

def nested_levels
  return 0 if data_for_nested_calls.empty?
  1 + data_for_nested_calls.collect {|nested_call_data| nested_call_data.nested_levels }.max
end

#to_entry(context_so_far = [], nesting_limit = 0) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/benchmarkable.rb', line 121

def to_entry(context_so_far = [], nesting_limit = 0)
  current_context = context_so_far + [@description]
  empty_context_columns = nesting_limit > 0 ? ['-'] * [nesting_limit, nested_levels].max : []
  current_entry = {:timestamp => @timestamp, :context => current_context + empty_context_columns, :execution_time => @overall_time}
  nested_entries = nesting_limit == 0 ? [] : 
    data_for_nested_calls.collect {|nested_call_data| nested_call_data.to_entry(current_context, nesting_limit - 1)}.flatten
  [current_entry] + nested_entries
end