add do_mysql to benchmarks

This commit is contained in:
Brian Lopez 2010-04-03 16:47:25 -07:00
parent b820100249
commit 31c0255451
2 changed files with 23 additions and 5 deletions

View File

@ -4,6 +4,7 @@ require 'rubygems'
require 'benchmark' require 'benchmark'
require 'mysql' require 'mysql'
require 'mysql2_ext' require 'mysql2_ext'
require 'do_mysql'
number_of = 1000 number_of = 1000
database = 'nbb_1_production' database = 'nbb_1_production'
@ -15,9 +16,7 @@ Benchmark.bmbm do |x|
x.report do x.report do
puts "Mysql" puts "Mysql"
number_of.times do number_of.times do
# NOTE: this uses mysql_escape_string in C mysql.quote str
# which is *not* encoding aware
mysql.escape_string str
end end
end end
@ -26,9 +25,15 @@ Benchmark.bmbm do |x|
x.report do x.report do
puts "Mysql2" puts "Mysql2"
number_of.times do number_of.times do
# NOTE: this uses mysql_real_escape_string in C
# which takes into account the encoding set on the connection
mysql2.escape str mysql2.escape str
end end
end end
do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
x.report do
puts "do_mysql"
number_of.times do
do_mysql.quote_string str
end
end
end end

View File

@ -4,6 +4,7 @@ require 'rubygems'
require 'benchmark' require 'benchmark'
require 'mysql' require 'mysql'
require 'mysql2_ext' require 'mysql2_ext'
require 'do_mysql'
number_of = 1 number_of = 1
database = 'nbb_1_production' database = 'nbb_1_production'
@ -22,6 +23,18 @@ Benchmark.bmbm do |x|
end 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
end
end
end
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root") mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2.query "USE #{database}" mysql2.query "USE #{database}"
x.report do x.report do