Skip to content

Instantly share code, notes, and snippets.

@m1foley
Last active December 18, 2015 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save m1foley/2948b486cf23e16040c5 to your computer and use it in GitHub Desktop.
Save m1foley/2948b486cf23e16040c5 to your computer and use it in GitHub Desktop.
FactoryGirl vs. Fixtures speed test
require "rails_helper"

describe "Speed Test" do
  it "uses fixtures" do
    10.times do
      users(:brad)
    end
  end

  it "uses FactoryGirl#create" do
    10.times do
      FactoryGirl.create(:presenter)
    end
  end

  it "uses FactoryGirl#build" do
    10.times do
      FactoryGirl.build(:presenter)
    end
  end
end
$ bundle exec rspec spec/models/speed_test_spec.rb:4
Speed Test
  uses fixtures

Finished in 3.19 seconds
1 example, 0 failures

$ bundle exec rspec spec/models/speed_test_spec.rb:10
Speed Test
  uses FactoryGirl#create

Finished in 11.07 seconds
1 example, 0 failures

$ bundle exec rspec spec/models/speed_test_spec.rb:16
Speed Test
  uses FactoryGirl#build

Finished in 3.35 seconds
1 example, 0 failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment