Created
December 31, 2012 05:36
-
-
Save bobbytables/4417572 to your computer and use it in GitHub Desktop.
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 'benchmark' | |
task :db_bench => :environment do | |
Benchmark.bm do |b| | |
b.report { 1.upto(10000) { User.first } } | |
b.report { 1.upto(10000) { User.select([:email, :default_edition_id]).first } } | |
b.report { 1.upto(10000) { User.first.created_at } } | |
b.report { 1.upto(10000) { User.select([:created_at, :default_edition_id]).first.created_at } } | |
b.report { 1.upto(10000) { ActiveRecord::Base.connection.execute("SELECT * FROM users LIMIT 1") } } | |
b.report { 1.upto(10000) { ActiveRecord::Base.connection.execute("SELECT email FROM users LIMIT 1") } } | |
end | |
end | |
# user system total real | |
# 2.980000 0.220000 3.200000 ( 3.837946) | |
# 2.410000 0.190000 2.600000 ( 3.037000) | |
# 3.070000 0.210000 3.280000 ( 3.913174) | |
# 2.620000 0.200000 2.820000 ( 3.260302) | |
# 0.810000 0.210000 1.020000 ( 1.573247) | |
# 0.740000 0.190000 0.930000 ( 1.306029) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So 80μs saved per query. How many rows/columns?