From 31c025545196620abbd4b5b6bcb88a603bea6fde Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Sat, 3 Apr 2010 16:47:25 -0700 Subject: [PATCH] add do_mysql to benchmarks --- benchmark/escape.rb | 15 ++++++++++----- benchmark/query.rb | 13 +++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/benchmark/escape.rb b/benchmark/escape.rb index ee7e64c..d9cb7a5 100644 --- a/benchmark/escape.rb +++ b/benchmark/escape.rb @@ -4,6 +4,7 @@ require 'rubygems' require 'benchmark' require 'mysql' require 'mysql2_ext' +require 'do_mysql' number_of = 1000 database = 'nbb_1_production' @@ -15,9 +16,7 @@ Benchmark.bmbm do |x| x.report do puts "Mysql" number_of.times do - # NOTE: this uses mysql_escape_string in C - # which is *not* encoding aware - mysql.escape_string str + mysql.quote str end end @@ -26,9 +25,15 @@ Benchmark.bmbm do |x| x.report do puts "Mysql2" 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 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 \ No newline at end of file diff --git a/benchmark/query.rb b/benchmark/query.rb index d6c59e4..c1018b0 100644 --- a/benchmark/query.rb +++ b/benchmark/query.rb @@ -4,6 +4,7 @@ require 'rubygems' require 'benchmark' require 'mysql' require 'mysql2_ext' +require 'do_mysql' number_of = 1 database = 'nbb_1_production' @@ -22,6 +23,18 @@ Benchmark.bmbm do |x| 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.query "USE #{database}" x.report do