Created
August 23, 2013 12:34
-
-
Save rosenfeld/6318820 to your computer and use it in GitHub Desktop.
factories overhead over fixtures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sequel' | |
require 'benchmark' | |
# createdb factories_test | |
DB = Sequel.connect 'postgres://localhost/factories_test' | |
DB.drop_table? :test | |
DB.create_table :test do | |
primary_key :id | |
String :name, null: false | |
index :name | |
end | |
class Test < Sequel::Model(:test);end | |
Test.count # warm-up | |
Benchmark.bm 40 do |x| | |
x.report 'Batch insert' do | |
DB << "insert into test(name) values " + (1..100).map{|i| "('name#{i}')"}.join(', ') | |
end | |
x.report "insert one at a time" do | |
100.times do |i| | |
DB << "insert into test(name) values('name#{i}')" | |
end | |
end | |
x.report "insert one at a time simulating factories" do | |
100.times do |i| | |
Test.new.tap{|t| t.name = "name#{i}"}.save | |
end | |
end | |
end | |
# user system total real | |
# Batch insert 0.000000 0.000000 0.000000 ( 0.020025) | |
# insert one at a time 0.010000 0.010000 0.020000 ( 1.446176) | |
# insert one at a time simulating factories 0.080000 0.010000 0.090000 ( 1.604117) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment