1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'rubygems'
require 'benchmark/ips'
require 'mysql'
require 'mysql2'
require 'do_mysql'
def run_escape_benchmarks(str)
Benchmark.ips do |x|
mysql = Mysql.new("localhost", "root")
x.report "Mysql #{str.inspect}" do
mysql.quote str
end
mysql2 = Mysql2::Client.new(host: "localhost", username: "root")
x.report "Mysql2 #{str.inspect}" do
mysql2.escape str
end
do_mysql = DataObjects::Connection.new("mysql://localhost/test")
x.report "do_mysql #{str.inspect}" do
do_mysql.quote_string str
end
x.compare!
end
end
run_escape_benchmarks "abc'def\"ghi\0jkl%mno"
run_escape_benchmarks "clean string"
|