Module: FactoryGirlInstruments::Benchmarking

Included in:
FactoryGirl
Defined in:
lib/factory_girl_instruments/benchmarking.rb

Instance Method Summary collapse

Instance Method Details

#benchmark(factory, method: :create) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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