mysql2/benchmark/escape.rb

39 lines
905 B
Ruby
Raw Permalink Normal View History

2010-04-01 19:04:55 +00:00
# encoding: UTF-8
2010-07-09 06:26:18 +00:00
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
2010-04-01 19:04:55 +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-04-01 19:04:55 +00:00
def run_escape_benchmarks(str, number_of = 1000)
Benchmark.bmbm do |x|
mysql = Mysql.new("localhost", "root")
x.report do
puts "Mysql #{str.inspect}"
number_of.times do
mysql.quote str
end
2010-04-01 19:04:55 +00:00
end
2010-04-03 08:35:41 +00:00
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
x.report do
puts "Mysql2 #{str.inspect}"
number_of.times do
mysql2.escape str
end
2010-04-01 19:04:55 +00:00
end
2010-04-03 23:47:25 +00:00
do_mysql = DataObjects::Connection.new("mysql://localhost/test")
x.report do
puts "do_mysql #{str.inspect}"
number_of.times do
do_mysql.quote_string str
end
2010-04-03 23:47:25 +00:00
end
end
end
run_escape_benchmarks "abc'def\"ghi\0jkl%mno"
run_escape_benchmarks "clean string"