Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. require 'active_support'
  2. require 'active_record'
  3. require 'benchmark/ips'
  4.  
  5. ActiveRecord::Base.establish_connection(
  6. adapter: 'mysql2',
  7. encoding: 'utf8',
  8. reconnect: true,
  9. pool: 25,
  10. host: 'localhost',
  11. database: 'test_database',
  12. username: 'root',
  13. password: ''
  14. )
  15.  
  16. class Customer < ActiveRecord::Base; end
  17.  
  18. name = 'Luciano Sousa'
  19.  
  20. Benchmark.ips do |x|
  21. x.report('where_first') { Customer.where(name: name).first }
  22. x.report('find_by_name') { Customer.find_by_name(name) }
  23. x.report('find_by') { Customer.find_by(name: name) }
  24. x.compare!
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement