Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement