Skip to content

Instantly share code, notes, and snippets.

@bobbytables
Created December 31, 2012 05:36
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 bobbytables/4417572 to your computer and use it in GitHub Desktop.
Save bobbytables/4417572 to your computer and use it in GitHub Desktop.
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)
@bloudermilk
Copy link

So 80μs saved per query. How many rows/columns?

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