module FactoryGirlInstruments::Benchmarking

Public Instance Methods

benchmark(factory, method: :create) click to toggle source
# File lib/factory_girl_instruments/benchmarking.rb, line 21
def benchmark(factory, method: :create)
  start = Time.now

  ActiveRecord::Base.transaction do
    FactoryGirl.public_send(method, factory)

    raise ActiveRecord::Rollback
  end

  Benchmark.new(factory, method, Time.now - start)
end
benchmark_all( except: [], methods: [:create, :build, :build_stubbed], progress: false) click to toggle source
# File lib/factory_girl_instruments/benchmarking.rb, line 3
def benchmark_all(
  except: [],
  methods: [:create, :build, :build_stubbed],
  progress: false)

  factories = FactoryGirl.factories.map(&:name) - except

  report = factories.map do |factory|
    puts "Processing #{factory}" if progress

    methods.map do |method|
      benchmark(factory, :method => method)
    end
  end

  report.flatten.sort_by(&:duration)
end