Guest User

Untitled

a guest
Apr 7th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. require 'benchmark'
  2. require 'rubygems'
  3. gem 'activerecord', '2.1'
  4. require 'active_record'
  5.  
  6. if defined? JRUBY_VERSION
  7. gem 'activerecord-jdbc-adapter'
  8. require 'jdbc_adapter'
  9. adapter = 'jdbcmysql'
  10. else
  11. adapter = 'mysql'
  12. end
  13.  
  14. # We assume that 'benchmark' database
  15. # exists, and populated with Post entries
  16.  
  17. ActiveRecord::Base.establish_connection(
  18. :adapter => adapter,
  19. :database => 'benchmark',
  20. :host => '127.0.0.1',
  21. :username => 'user',
  22. :password => 'pass'
  23. )
  24.  
  25. class Post < ActiveRecord::Base
  26. end
  27.  
  28. # Populate the table first.
  29. # 50.times { |i|
  30. # Post.new(:title=>"TITLE#{i}", :body=>"BODY#{i}", :published=> true).save
  31. # }
  32.  
  33. (ARGV[0] || 5).to_i.times do
  34. Benchmark.bm(35) { |bm|
  35. bm.report("15K AR::Base.find(:first)") {
  36. 15_000.times { Post.find(:first) }
  37. }
  38. bm.report("15K AR::Base.find(:last)") {
  39. 15_000.times { Post.find(:last) }
  40. }
  41. bm.report("10K AR::Base.find(:all)") {
  42. 10_000.times { Post.find(:all) }
  43. }
  44. }
  45. end
Add Comment
Please, Sign In to add comment