Skip to content

Instantly share code, notes, and snippets.

@ixti
Created July 25, 2014 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ixti/f258a223fbbe568c2e12 to your computer and use it in GitHub Desktop.
Save ixti/f258a223fbbe568c2e12 to your computer and use it in GitHub Desktop.
require "benchmark/ips"
require "factory_girl"
require "fabrication"
require "mongo_mapper"
class Foo
include MongoMapper::Document
key :name
key :email
end
Fabricator :foo do
name { %w[alice bob charlie].sample }
email { |attrs| sequence { |i| "#{attrs[:name]}-#{i}gmail.com" } }
end
FactoryGirl.define do
factory :foo do
name { %w[alice bob charlie].sample }
sequence(:email) { |i| "#{name}-#{i}gmail.com" }
end
end
Benchmark.ips do |x|
x.config :time => 5, :warmup => 2
x.report("Fabrication") { Fabricate.build :foo }
x.report("FactoryGirl") { FactoryGirl.build :foo }
end
@ixti
Copy link
Author

ixti commented Jul 25, 2014

Calculating -------------------------------------
         Fabrication       936 i/100ms
         FactoryGirl       586 i/100ms
-------------------------------------------------
         Fabrication    10676.9 (±9.8%) i/s -      53352 in   5.043164s
         FactoryGirl     6320.4 (±10.1%) i/s -      31644 in   5.057256s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment