mysql2/benchmark/escape.rb

34 lines
779 B
Ruby
Raw Normal View History

2010-04-01 19:04:55 +00:00
# encoding: UTF-8
require 'rubygems'
require 'benchmark'
require 'mysql'
require 'mysql2_ext'
number_of = 1000
database = 'nbb_1_production'
str = "abc'def\"ghi\0jkl%mno"
Benchmark.bmbm do |x|
mysql = Mysql.new("localhost", "root")
mysql.query "USE #{database}"
x.report do
puts "Mysql"
number_of.times do
2010-04-03 08:45:41 +00:00
# NOTE: this uses mysql_escape_string in C
# which is *not* encoding aware
2010-04-01 19:04:55 +00:00
mysql.escape_string str
end
end
2010-04-03 08:35:41 +00:00
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
2010-04-01 19:04:55 +00:00
mysql2.query "USE #{database}"
x.report do
puts "Mysql2"
number_of.times do
2010-04-03 08:45:41 +00:00
# NOTE: this uses mysql_real_escape_string in C
# which takes into account the encoding set on the connection
2010-04-01 19:04:55 +00:00
mysql2.escape str
end
end
end