2010-03-30 17:18:29 +00:00
|
|
|
# encoding: UTF-8
|
2010-07-09 06:26:18 +00:00
|
|
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
2010-03-30 17:18:29 +00:00
|
|
|
|
|
|
|
require 'rubygems'
|
2010-03-31 15:56:07 +00:00
|
|
|
require 'benchmark'
|
|
|
|
require 'mysql'
|
2010-07-09 06:26:18 +00:00
|
|
|
require 'mysql2'
|
2010-04-03 23:47:25 +00:00
|
|
|
require 'do_mysql'
|
2010-03-30 17:18:29 +00:00
|
|
|
|
2010-04-21 08:31:46 +00:00
|
|
|
number_of = 100
|
2010-04-06 08:16:37 +00:00
|
|
|
database = 'test'
|
2010-04-21 08:31:46 +00:00
|
|
|
sql = "SELECT * FROM mysql2_test LIMIT 100"
|
2010-03-30 17:18:29 +00:00
|
|
|
|
2010-03-31 15:56:07 +00:00
|
|
|
Benchmark.bmbm do |x|
|
2010-04-06 08:16:37 +00:00
|
|
|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
|
|
|
|
mysql2.query "USE #{database}"
|
2010-03-31 15:56:07 +00:00
|
|
|
x.report do
|
2010-04-06 08:16:37 +00:00
|
|
|
puts "Mysql2"
|
2010-03-31 15:56:07 +00:00
|
|
|
number_of.times do
|
2010-08-02 03:20:48 +00:00
|
|
|
mysql2_result = mysql2.query sql, :symbolize_keys => true
|
|
|
|
mysql2_result.each do |res|
|
2010-03-30 23:40:41 +00:00
|
|
|
# puts res.inspect
|
2010-03-31 15:56:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-03-30 17:18:29 +00:00
|
|
|
|
2010-04-06 08:16:37 +00:00
|
|
|
mysql = Mysql.new("localhost", "root")
|
|
|
|
mysql.query "USE #{database}"
|
2010-04-03 23:47:25 +00:00
|
|
|
x.report do
|
2010-04-06 08:16:37 +00:00
|
|
|
puts "Mysql"
|
2010-04-03 23:47:25 +00:00
|
|
|
number_of.times do
|
2010-04-06 08:16:37 +00:00
|
|
|
mysql_result = mysql.query sql
|
|
|
|
mysql_result.each_hash do |res|
|
2010-04-03 23:47:25 +00:00
|
|
|
# puts res.inspect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-05 05:51:38 +00:00
|
|
|
do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
|
|
|
|
command = DataObjects::Mysql::Command.new do_mysql, sql
|
2010-03-31 15:56:07 +00:00
|
|
|
x.report do
|
2010-04-05 05:51:38 +00:00
|
|
|
puts "do_mysql"
|
2010-03-31 15:56:07 +00:00
|
|
|
number_of.times do
|
2010-04-05 05:51:38 +00:00
|
|
|
do_result = command.execute_reader
|
|
|
|
do_result.each do |res|
|
2010-03-31 15:56:07 +00:00
|
|
|
# puts res.inspect
|
2010-03-30 23:40:41 +00:00
|
|
|
end
|
2010-03-31 15:56:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|