Skip to content

Instantly share code, notes, and snippets.

@kaichen
Created July 22, 2011 04:13
Show Gist options
  • Select an option

  • Save kaichen/1098870 to your computer and use it in GitHub Desktop.

Select an option

Save kaichen/1098870 to your computer and use it in GitHub Desktop.
require "rubygems"
require "active_record"
require "squeel"
n = 5000
conn = { :adapter => 'sqlite3', :database => ':memory:' }
ActiveRecord::Base.establish_connection(conn)
class User < ActiveRecord::Base
connection.create_table :users, :force => true do |t|
t.string :name, :email
end
end
User.create :name => "Joe Blow", :email => "[email protected]"
User.create :name => "Jack Nack", :email => "[email protected]"
User.create :name => "Gerdon Don", :email => "[email protected]"
Benchmark.bmbm do |x|
x.report("w/o squeel") { for i in 1..n; User.where(:name => 'Joe Blow'); end }
x.report("w/ squeel") { for i in 1..n; User.where{name.eq 'Joe Blow'}; end }
end
#=>
# user system total real
# w/o squeel 0.100000 0.000000 0.100000 ( 0.109199)
# w/ squeel 0.220000 0.010000 0.230000 ( 0.253682)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment