Last active
January 15, 2016 01:09
-
-
Save lucianosousa/642e182eec4f6da356cb to your computer and use it in GitHub Desktop.
Second benchmark for AR queries
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 'active_support' | |
require 'active_record' | |
require 'benchmark/ips' | |
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' | |
ActiveRecord::Base.connection.instance_eval do | |
create_table(:customers) { |c| c.string :name } | |
end | |
class Customer < ActiveRecord::Base; end | |
name = 'Luciano Sousa' | |
Customer.create! name: name | |
Benchmark.ips do |x| | |
x.report('where_first') { Customer.where(name: name).first } | |
x.report('find_by_name') { Customer.find_by_name(name) } | |
x.report('find_by') { Customer.find_by(name: name) } | |
x.compare! | |
end |
Author
lucianosousa
commented
Jan 15, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment