class FactoryGirlProfiling::Profiler

Attributes

output_buffer[W]

Public Class Methods

instance() click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 4
def self.instance
  @instance ||= new
end
new() click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 16
def initialize
  reset
end

Public Instance Methods

add(name, start, finish, id, payload) click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 25
def add(name, start, finish, id, payload)
  add_counting(payload[:name], payload[:strategy])
  add_timing(payload[:name], payload[:strategy], finish - start)
end
add_counting(name, strategy) click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 41
def add_counting(name, strategy)
  @factory_girl_results[name] ||= {}
  @factory_girl_results[name][strategy] ||= 0
  @factory_girl_results[name][strategy] += 1
end
add_timing(name, strategy, timing) click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 30
def add_timing(name, strategy, timing)
  @factory_girl_timing_results[name] ||= {}
  @factory_girl_timing_results[name][strategy] ||= []
  @factory_girl_timing_results[name][strategy] << timing


  #if timing >= 0.5
  #output_string "Slow factory: #{name} using strategy #{strategy}"
  #end
end
output_buffer() click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 84
def output_buffer
  @output_buffer ||= $stdout
end
output_string(str) click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 79
def output_string(str)
  output_buffer.puts str
end
print_counting_results() click to toggle source
print_results() click to toggle source
print_timing_results() click to toggle source
reset() click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 20
def reset
  @factory_girl_results = {}
  @factory_girl_timing_results = {}
end
sort_data_hash(hash, sort_value_proc = nil) click to toggle source
# File lib/factory_girl_profiling/profiler.rb, line 74
def sort_data_hash(hash, sort_value_proc = nil)
  sort_value_proc ||= Proc.new {|val| val.values.reduce(0, &:+) }
  hash.to_a.sort {|(_, v1), (_, v2)| sort_value_proc.call(v2) <=> sort_value_proc.call(v1)}
end