forked from brianmario/mysql2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_without_mysql_casting.rb
56 lines (50 loc) · 1.36 KB
/
query_without_mysql_casting.rb
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# encoding: UTF-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'rubygems'
require 'benchmark'
require 'mysql'
require 'mysql2'
require 'do_mysql'
number_of = 100
database = 'test'
sql = "SELECT * FROM mysql2_test LIMIT 100"
Benchmark.bmbm do |x|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2.query "USE #{database}"
x.report "Mysql2 (cast: true)" do
number_of.times do
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => true
mysql2_result.each do |res|
# puts res.inspect
end
end
end
x.report "Mysql2 (cast: false)" do
number_of.times do
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => false
mysql2_result.each do |res|
# puts res.inspect
end
end
end
mysql = Mysql.new("localhost", "root")
mysql.query "USE #{database}"
x.report "Mysql" do
number_of.times do
mysql_result = mysql.query sql
mysql_result.each_hash do |res|
# puts res.inspect
end
end
end
do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
command = DataObjects::Mysql::Command.new do_mysql, sql
x.report "do_mysql" do
number_of.times do
do_result = command.execute_reader
do_result.each do |res|
# puts res.inspect
end
end
end
end