Guest User

Untitled

a guest
Jun 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'rubygems'
  4. require 'sqlite3'
  5. require 'benchmark'
  6. require File.expand_path("../../../load_paths", __FILE__)
  7. require 'active_record'
  8.  
  9. ActiveRecord::Base.establish_connection(:adapter => 'sqlite3',
  10. :database => ':memory:')
  11.  
  12. class User < ActiveRecord::Base
  13. connection.create_table :users, :force => true do |t|
  14. end
  15. end
  16.  
  17. Benchmark.bm do |x|
  18. x.report 'Model#find_by_id' do
  19. 100_000.times do
  20. User.find_by_id(1)
  21. end
  22. end
  23. end
  24.  
  25. # MRI 1.8.7
  26. # without caching find_by_* methods
  27. # user system total real
  28. # Model#find_by_id 33.050000 1.060000 34.110000 ( 37.705276)
  29.  
  30. # caching find_by_* methods
  31. # user system total real
  32. # Model#find_by_id 29.550000 0.880000 30.430000 ( 31.797355)
  33.  
  34.  
  35. # MRI 1.9.2
  36. # without caching find_by_* methods
  37. # user system total real
  38. # Model#find_by_id 25.250000 0.170000 25.420000 ( 27.110316)
  39.  
  40. # caching find_by_* methods
  41. # user system total real
  42. # Model#find_by_id 23.190000 0.140000 23.330000 ( 24.353884)
Add Comment
Please, Sign In to add comment