mysql2/benchmark/query_without_mysql_casting.rb

50 lines
1.1 KiB
Ruby
Raw Normal View History

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'
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
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
Benchmark.bmbm do |x|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2.query "USE #{database}"
x.report do
puts "Mysql2"
number_of.times do
mysql2_result = mysql2.query sql, :symbolize_keys => true
mysql2_result.each do |res|
2010-03-30 23:40:41 +00:00
# puts res.inspect
end
end
end
2010-03-30 17:18:29 +00:00
mysql = Mysql.new("localhost", "root")
mysql.query "USE #{database}"
2010-04-03 23:47:25 +00:00
x.report do
puts "Mysql"
2010-04-03 23:47:25 +00:00
number_of.times do
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
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
2010-03-30 23:40:41 +00:00
end
end
end
end