-
-
Save sahidursuman/46fd06aca69056f01c1a294779a302d2 to your computer and use it in GitHub Desktop.
Comparing runtime characteristics of individual transactions, one transaction, and one statement.
This file contains hidden or 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
def insert_many | |
1000.times { SeoRank.create! } | |
end | |
start = Time.now | |
ActiveRecord::Base.transaction { insert_many } | |
puts "N transactions: #{ Time.now - start }" | |
start = Time.now | |
ActiveRecord::Base.transaction { insert_many } | |
puts "One transaction: #{ Time.now - start }" | |
values = (["('a')"] * 1000).join(',') | |
start = Time.now | |
ActiveRecord::Base.connection.execute "insert into seo_ranks (href) values #{ values }" | |
puts "Hand rolled SQL: #{ Time.now - start }" | |
$ be rails runner "$( cat transaction.rb )" | |
N transactions: 1.390017 | |
One transaction: 1.110242 | |
Hand rolled SQL: 0.011879 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment