mysql2/benchmark/query.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

2010-03-30 17:18:29 +00:00
# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'mysql'
2010-03-30 17:18:29 +00:00
require 'mysql2_ext'
2010-04-03 23:47:25 +00:00
require 'do_mysql'
2010-03-30 17:18:29 +00:00
2010-03-30 23:40:41 +00:00
number_of = 1
database = 'nbb_1_production'
2010-04-01 06:01:35 +00:00
sql = "SELECT * FROM account_entries"
2010-03-30 17:18:29 +00:00
Benchmark.bmbm do |x|
mysql = Mysql.new("localhost", "root")
mysql.query "USE #{database}"
x.report do
puts "Mysql"
number_of.times do
mysql_result = mysql.query sql
mysql_result.each_hash do |res|
2010-03-30 23:40:41 +00:00
# puts res.inspect
end
end
end
2010-03-30 17:18:29 +00:00
2010-04-03 23:47:25 +00:00
do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
command = DataObjects::Mysql::Command.new do_mysql, sql
x.report do
puts "do_mysql"
number_of.times do
do_result = command.execute_reader
do_result.each do |res|
# puts res.inspect
end
end
end
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
2010-03-30 23:40:41 +00:00
mysql2.query "USE #{database}"
x.report do
puts "Mysql2"
number_of.times do
mysql2_result = mysql2.query sql
2010-03-30 23:40:41 +00:00
mysql2_result.each(:symbolize_keys => true) do |res|
# puts res.inspect
2010-03-30 23:40:41 +00:00
end
end
end
end