Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'mysql2'
  4.  
  5. NUM_OF_TRANSACTIONS = ARGV[0] || 10_000
  6.  
  7. module Bench
  8. class ActiveRecord
  9. attr_accessor :execution_time
  10.  
  11. def benchmark!
  12. @start = Time.now
  13.  
  14. NUM_OF_TRANSACTIONS.times do |_|
  15. ::Order.where("id > 20 ", 10)
  16. end
  17.  
  18. @finish = Time.now
  19. @execution_time = @finish - @start
  20. end
  21. end
  22.  
  23. class Mysql2
  24. attr_accessor :execution_time
  25.  
  26. def initialize
  27. @client = ::Mysql2::Client.new(
  28. :host => ENV.fetch('DATABASE_HOST', '127.0.0.1'),
  29. :username => ENV.fetch('DATABASE_USER', 'root'),
  30. :port => 3306,
  31. :password => ENV['DATABASE_PASS'],
  32. :database => ENV.fetch('DATABASE_NAME', 'peatio_development')
  33. )
  34. end
  35.  
  36. def benchmark!
  37. @start = Time.now
  38.  
  39. NUM_OF_TRANSACTIONS.times do |_|
  40. @client.query("SELECT * FROM orders WHERE id > #{10}")
  41. end
  42.  
  43. @finish = Time.now
  44. @execution_time = @finish - @start
  45. end
  46. end
  47. end
  48.  
  49. ar_bench = Bench::ActiveRecord.new
  50. my_bench = Bench::Mysql2.new
  51.  
  52. ar_bench.benchmark!
  53. my_bench.benchmark!
  54.  
  55. puts ar_bench.execution_time
  56. puts my_bench.execution_time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement