Skip additional string length access in rb_mysql_client_escape and benchmark escaping "clean" strings as well
This commit is contained in:
parent
931765ee05
commit
f601c3cef8
@ -7,13 +7,11 @@ require 'mysql'
|
|||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
require 'do_mysql'
|
require 'do_mysql'
|
||||||
|
|
||||||
number_of = 1000
|
def run_escape_benchmarks(str, number_of = 1000)
|
||||||
str = "abc'def\"ghi\0jkl%mno"
|
Benchmark.bmbm do |x|
|
||||||
|
|
||||||
Benchmark.bmbm do |x|
|
|
||||||
mysql = Mysql.new("localhost", "root")
|
mysql = Mysql.new("localhost", "root")
|
||||||
x.report do
|
x.report do
|
||||||
puts "Mysql"
|
puts "Mysql #{str.inspect}"
|
||||||
number_of.times do
|
number_of.times do
|
||||||
mysql.quote str
|
mysql.quote str
|
||||||
end
|
end
|
||||||
@ -21,7 +19,7 @@ Benchmark.bmbm do |x|
|
|||||||
|
|
||||||
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
|
||||||
x.report do
|
x.report do
|
||||||
puts "Mysql2"
|
puts "Mysql2 #{str.inspect}"
|
||||||
number_of.times do
|
number_of.times do
|
||||||
mysql2.escape str
|
mysql2.escape str
|
||||||
end
|
end
|
||||||
@ -29,9 +27,13 @@ Benchmark.bmbm do |x|
|
|||||||
|
|
||||||
do_mysql = DataObjects::Connection.new("mysql://localhost/test")
|
do_mysql = DataObjects::Connection.new("mysql://localhost/test")
|
||||||
x.report do
|
x.report do
|
||||||
puts "do_mysql"
|
puts "do_mysql #{str.inspect}"
|
||||||
number_of.times do
|
number_of.times do
|
||||||
do_mysql.quote_string str
|
do_mysql.quote_string str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
run_escape_benchmarks "abc'def\"ghi\0jkl%mno"
|
||||||
|
run_escape_benchmarks "clean string"
|
@ -335,7 +335,7 @@ static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
|
|||||||
Data_Get_Struct(self, MYSQL, client);
|
Data_Get_Struct(self, MYSQL, client);
|
||||||
|
|
||||||
REQUIRE_OPEN_DB(client);
|
REQUIRE_OPEN_DB(client);
|
||||||
newLen = mysql_real_escape_string(client, escaped, StringValuePtr(str), RSTRING_LEN(str));
|
newLen = mysql_real_escape_string(client, escaped, StringValuePtr(str), oldLen);
|
||||||
if (newLen == oldLen) {
|
if (newLen == oldLen) {
|
||||||
// no need to return a new ruby string if nothing changed
|
// no need to return a new ruby string if nothing changed
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
Reference in New Issue
Block a user