Created
January 15, 2016 00:42
-
-
Save lucianosousa/5f188167b1f907e0f34f to your computer and use it in GitHub Desktop.
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
require 'active_support' | |
require 'active_record' | |
require 'benchmark/ips' | |
ActiveRecord::Base.establish_connection( | |
adapter: 'mysql2', | |
encoding: 'utf8', | |
reconnect: true, | |
pool: 25, | |
host: 'localhost', | |
database: 'test_database', | |
username: 'root', | |
password: '' | |
) | |
class Customer < ActiveRecord::Base; end | |
name = 'Luciano Sousa' | |
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