Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'mysql2'
- NUM_OF_TRANSACTIONS = ARGV[0] || 10_000
- module Bench
- class ActiveRecord
- attr_accessor :execution_time
- def benchmark!
- @start = Time.now
- NUM_OF_TRANSACTIONS.times do |_|
- ::Order.where("id > 20 ", 10)
- end
- @finish = Time.now
- @execution_time = @finish - @start
- end
- end
- class Mysql2
- attr_accessor :execution_time
- def initialize
- @client = ::Mysql2::Client.new(
- :host => ENV.fetch('DATABASE_HOST', '127.0.0.1'),
- :username => ENV.fetch('DATABASE_USER', 'root'),
- :port => 3306,
- :password => ENV['DATABASE_PASS'],
- :database => ENV.fetch('DATABASE_NAME', 'peatio_development')
- )
- end
- def benchmark!
- @start = Time.now
- NUM_OF_TRANSACTIONS.times do |_|
- @client.query("SELECT * FROM orders WHERE id > #{10}")
- end
- @finish = Time.now
- @execution_time = @finish - @start
- end
- end
- end
- ar_bench = Bench::ActiveRecord.new
- my_bench = Bench::Mysql2.new
- ar_bench.benchmark!
- my_bench.benchmark!
- puts ar_bench.execution_time
- puts my_bench.execution_time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement