mysql2 0.3.8 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -220
  3. data/LICENSE +21 -0
  4. data/README.md +370 -79
  5. data/examples/eventmachine.rb +1 -1
  6. data/examples/threaded.rb +4 -6
  7. data/ext/mysql2/client.c +1017 -305
  8. data/ext/mysql2/client.h +35 -11
  9. data/ext/mysql2/extconf.rb +222 -34
  10. data/ext/mysql2/infile.c +122 -0
  11. data/ext/mysql2/infile.h +1 -0
  12. data/ext/mysql2/mysql2_ext.c +1 -0
  13. data/ext/mysql2/mysql2_ext.h +12 -14
  14. data/ext/mysql2/mysql_enc_name_to_ruby.h +168 -0
  15. data/ext/mysql2/mysql_enc_to_ruby.h +249 -0
  16. data/ext/mysql2/result.c +664 -166
  17. data/ext/mysql2/result.h +16 -6
  18. data/ext/mysql2/statement.c +595 -0
  19. data/ext/mysql2/statement.h +19 -0
  20. data/lib/mysql2/client.rb +118 -211
  21. data/lib/mysql2/console.rb +5 -0
  22. data/lib/mysql2/em.rb +23 -5
  23. data/lib/mysql2/error.rb +62 -6
  24. data/lib/mysql2/field.rb +3 -0
  25. data/lib/mysql2/statement.rb +17 -0
  26. data/lib/mysql2/version.rb +1 -1
  27. data/lib/mysql2.rb +66 -3
  28. data/spec/configuration.yml.example +11 -0
  29. data/spec/em/em_spec.rb +96 -10
  30. data/spec/my.cnf.example +9 -0
  31. data/spec/mysql2/client_spec.rb +779 -205
  32. data/spec/mysql2/error_spec.rb +58 -45
  33. data/spec/mysql2/result_spec.rb +316 -159
  34. data/spec/mysql2/statement_spec.rb +776 -0
  35. data/spec/spec_helper.rb +97 -56
  36. data/spec/ssl/ca-cert.pem +17 -0
  37. data/spec/ssl/ca-key.pem +27 -0
  38. data/spec/ssl/ca.cnf +22 -0
  39. data/spec/ssl/cert.cnf +22 -0
  40. data/spec/ssl/client-cert.pem +17 -0
  41. data/spec/ssl/client-key.pem +27 -0
  42. data/spec/ssl/client-req.pem +15 -0
  43. data/spec/ssl/gen_certs.sh +48 -0
  44. data/spec/ssl/pkcs8-client-key.pem +28 -0
  45. data/spec/ssl/pkcs8-server-key.pem +28 -0
  46. data/spec/ssl/server-cert.pem +17 -0
  47. data/spec/ssl/server-key.pem +27 -0
  48. data/spec/ssl/server-req.pem +15 -0
  49. data/spec/test_data +1 -0
  50. data/support/5072E1F5.asc +432 -0
  51. data/support/libmysql.def +219 -0
  52. data/support/mysql_enc_to_ruby.rb +81 -0
  53. data/support/ruby_enc_to_mysql.rb +61 -0
  54. metadata +77 -196
  55. data/.gitignore +0 -12
  56. data/.rspec +0 -3
  57. data/.rvmrc +0 -1
  58. data/.travis.yml +0 -7
  59. data/Gemfile +0 -3
  60. data/MIT-LICENSE +0 -20
  61. data/Rakefile +0 -5
  62. data/benchmark/active_record.rb +0 -51
  63. data/benchmark/active_record_threaded.rb +0 -42
  64. data/benchmark/allocations.rb +0 -33
  65. data/benchmark/escape.rb +0 -36
  66. data/benchmark/query_with_mysql_casting.rb +0 -80
  67. data/benchmark/query_without_mysql_casting.rb +0 -56
  68. data/benchmark/sequel.rb +0 -37
  69. data/benchmark/setup_db.rb +0 -119
  70. data/benchmark/threaded.rb +0 -44
  71. data/mysql2.gemspec +0 -29
  72. data/tasks/benchmarks.rake +0 -20
  73. data/tasks/compile.rake +0 -71
  74. data/tasks/rspec.rake +0 -16
  75. data/tasks/vendor_mysql.rake +0 -40
@@ -0,0 +1,81 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'mysql2'
3
+
4
+ user, pass, host, port = ENV.values_at('user', 'pass', 'host', 'port')
5
+
6
+ mysql_to_rb = {
7
+ "big5" => "Big5",
8
+ "dec8" => "NULL",
9
+ "cp850" => "CP850",
10
+ "hp8" => "NULL",
11
+ "koi8r" => "KOI8-R",
12
+ "latin1" => "ISO-8859-1",
13
+ "latin2" => "ISO-8859-2",
14
+ "swe7" => "NULL",
15
+ "ascii" => "US-ASCII",
16
+ "ujis" => "eucJP-ms",
17
+ "sjis" => "Shift_JIS",
18
+ "hebrew" => "ISO-8859-8",
19
+ "tis620" => "TIS-620",
20
+ "euckr" => "EUC-KR",
21
+ "koi8u" => "KOI8-R",
22
+ "gb2312" => "GB2312",
23
+ "greek" => "ISO-8859-7",
24
+ "cp1250" => "Windows-1250",
25
+ "gbk" => "GBK",
26
+ "latin5" => "ISO-8859-9",
27
+ "armscii8" => "NULL",
28
+ "utf8" => "UTF-8",
29
+ "ucs2" => "UTF-16BE",
30
+ "cp866" => "IBM866",
31
+ "keybcs2" => "NULL",
32
+ "macce" => "macCentEuro",
33
+ "macroman" => "macRoman",
34
+ "cp852" => "CP852",
35
+ "latin7" => "ISO-8859-13",
36
+ "utf8mb4" => "UTF-8",
37
+ "cp1251" => "Windows-1251",
38
+ "utf16" => "UTF-16",
39
+ "cp1256" => "Windows-1256",
40
+ "cp1257" => "Windows-1257",
41
+ "utf32" => "UTF-32",
42
+ "binary" => "ASCII-8BIT",
43
+ "geostd8" => "NULL",
44
+ "cp932" => "Windows-31J",
45
+ "eucjpms" => "eucJP-ms",
46
+ }
47
+
48
+ client = Mysql2::Client.new(:username => user, :password => pass, :host => host, :port => port.to_i)
49
+ collations = client.query "SHOW COLLATION", :as => :array
50
+ encodings = Array.new(collations.to_a.last[2].to_i)
51
+ encodings_with_nil = Array.new(encodings.size)
52
+
53
+ collations.each do |collation|
54
+ mysql_col_idx = collation[2].to_i
55
+ rb_enc = mysql_to_rb[collation[1]]
56
+ encodings[mysql_col_idx - 1] = [mysql_col_idx, rb_enc]
57
+ end
58
+
59
+ encodings.each_with_index do |encoding, idx|
60
+ encodings_with_nil[idx] = (encoding || [idx, "NULL"])
61
+ end
62
+
63
+ encodings_with_nil.sort! do |a, b|
64
+ a[0] <=> b[0]
65
+ end
66
+
67
+ encodings_with_nil = encodings_with_nil.map do |encoding|
68
+ name = if encoding.nil? || encoding[1] == 'NULL'
69
+ 'NULL'
70
+ else
71
+ "\"#{encoding[1]}\""
72
+ end
73
+
74
+ " #{name}"
75
+ end
76
+
77
+ # start printing output
78
+
79
+ puts "static const char *mysql2_mysql_enc_to_rb[] = {"
80
+ puts encodings_with_nil.join(",\n")
81
+ puts "};"
@@ -0,0 +1,61 @@
1
+ mysql_to_rb = {
2
+ "big5" => "Big5",
3
+ "dec8" => nil,
4
+ "cp850" => "CP850",
5
+ "hp8" => nil,
6
+ "koi8r" => "KOI8-R",
7
+ "latin1" => "ISO-8859-1",
8
+ "latin2" => "ISO-8859-2",
9
+ "swe7" => nil,
10
+ "ascii" => "US-ASCII",
11
+ "ujis" => "eucJP-ms",
12
+ "sjis" => "Shift_JIS",
13
+ "hebrew" => "ISO-8859-8",
14
+ "tis620" => "TIS-620",
15
+ "euckr" => "EUC-KR",
16
+ "koi8u" => "KOI8-R",
17
+ "gb2312" => "GB2312",
18
+ "greek" => "ISO-8859-7",
19
+ "cp1250" => "Windows-1250",
20
+ "gbk" => "GBK",
21
+ "latin5" => "ISO-8859-9",
22
+ "armscii8" => nil,
23
+ "utf8" => "UTF-8",
24
+ "ucs2" => "UTF-16BE",
25
+ "cp866" => "IBM866",
26
+ "keybcs2" => nil,
27
+ "macce" => "macCentEuro",
28
+ "macroman" => "macRoman",
29
+ "cp852" => "CP852",
30
+ "latin7" => "ISO-8859-13",
31
+ "utf8mb4" => "UTF-8",
32
+ "cp1251" => "Windows-1251",
33
+ "utf16" => "UTF-16",
34
+ "cp1256" => "Windows-1256",
35
+ "cp1257" => "Windows-1257",
36
+ "utf32" => "UTF-32",
37
+ "binary" => "ASCII-8BIT",
38
+ "geostd8" => nil,
39
+ "cp932" => "Windows-31J",
40
+ "eucjpms" => "eucJP-ms",
41
+ }
42
+
43
+ puts <<-header
44
+ %readonly-tables
45
+ %enum
46
+ %define lookup-function-name mysql2_mysql_enc_name_to_rb
47
+ %define hash-function-name mysql2_mysql_enc_name_to_rb_hash
48
+ %struct-type
49
+ struct mysql2_mysql_enc_name_to_rb_map { const char *name; const char *rb_name; }
50
+ %%
51
+ header
52
+
53
+ mysql_to_rb.each do |mysql, ruby|
54
+ if ruby.nil?
55
+ name = "NULL"
56
+ else
57
+ name = "\"#{ruby}\""
58
+ end
59
+
60
+ puts "#{mysql}, #{name}"
61
+ end
metadata CHANGED
@@ -1,247 +1,128 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mysql2
3
- version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 8
10
- version: 0.3.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.10
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Brian Lopez
8
+ - Aaron Stone
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-09 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: eventmachine
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rake-compiler
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 13
44
- segments:
45
- - 0
46
- - 7
47
- - 7
48
- version: 0.7.7
49
- type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rake
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - "="
58
- - !ruby/object:Gem::Version
59
- hash: 49
60
- segments:
61
- - 0
62
- - 8
63
- - 7
64
- version: 0.8.7
65
- type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: rspec
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
79
- type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: activerecord
83
- prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- type: :development
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
96
- name: mysql
97
- prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
99
- none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- type: :development
108
- version_requirements: *id006
109
- - !ruby/object:Gem::Dependency
110
- name: do_mysql
111
- prerelease: false
112
- requirement: &id007 !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
121
- type: :development
122
- version_requirements: *id007
123
- - !ruby/object:Gem::Dependency
124
- name: sequel
125
- prerelease: false
126
- requirement: &id008 !ruby/object:Gem::Requirement
127
- none: false
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
- version: "0"
135
- type: :development
136
- version_requirements: *id008
137
- - !ruby/object:Gem::Dependency
138
- name: faker
139
- prerelease: false
140
- requirement: &id009 !ruby/object:Gem::Requirement
141
- none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- hash: 3
146
- segments:
147
- - 0
148
- version: "0"
149
- type: :development
150
- version_requirements: *id009
12
+ date: 2017-11-14 00:00:00.000000000 Z
13
+ dependencies: []
151
14
  description:
152
- email: seniorlopez@gmail.com
15
+ email:
16
+ - seniorlopez@gmail.com
17
+ - aaron@serendipity.cx
153
18
  executables: []
154
-
155
- extensions:
19
+ extensions:
156
20
  - ext/mysql2/extconf.rb
157
21
  extra_rdoc_files: []
158
-
159
- files:
160
- - .gitignore
161
- - .rspec
162
- - .rvmrc
163
- - .travis.yml
22
+ files:
164
23
  - CHANGELOG.md
165
- - Gemfile
166
- - MIT-LICENSE
24
+ - LICENSE
167
25
  - README.md
168
- - Rakefile
169
- - benchmark/active_record.rb
170
- - benchmark/active_record_threaded.rb
171
- - benchmark/allocations.rb
172
- - benchmark/escape.rb
173
- - benchmark/query_with_mysql_casting.rb
174
- - benchmark/query_without_mysql_casting.rb
175
- - benchmark/sequel.rb
176
- - benchmark/setup_db.rb
177
- - benchmark/threaded.rb
178
26
  - examples/eventmachine.rb
179
27
  - examples/threaded.rb
180
28
  - ext/mysql2/client.c
181
29
  - ext/mysql2/client.h
182
30
  - ext/mysql2/extconf.rb
31
+ - ext/mysql2/infile.c
32
+ - ext/mysql2/infile.h
183
33
  - ext/mysql2/mysql2_ext.c
184
34
  - ext/mysql2/mysql2_ext.h
35
+ - ext/mysql2/mysql_enc_name_to_ruby.h
36
+ - ext/mysql2/mysql_enc_to_ruby.h
185
37
  - ext/mysql2/result.c
186
38
  - ext/mysql2/result.h
39
+ - ext/mysql2/statement.c
40
+ - ext/mysql2/statement.h
187
41
  - ext/mysql2/wait_for_single_fd.h
188
42
  - lib/mysql2.rb
189
43
  - lib/mysql2/client.rb
44
+ - lib/mysql2/console.rb
190
45
  - lib/mysql2/em.rb
191
46
  - lib/mysql2/error.rb
47
+ - lib/mysql2/field.rb
192
48
  - lib/mysql2/result.rb
49
+ - lib/mysql2/statement.rb
193
50
  - lib/mysql2/version.rb
194
- - mysql2.gemspec
51
+ - spec/configuration.yml.example
195
52
  - spec/em/em_spec.rb
53
+ - spec/my.cnf.example
196
54
  - spec/mysql2/client_spec.rb
197
55
  - spec/mysql2/error_spec.rb
198
56
  - spec/mysql2/result_spec.rb
57
+ - spec/mysql2/statement_spec.rb
199
58
  - spec/rcov.opts
200
59
  - spec/spec_helper.rb
201
- - tasks/benchmarks.rake
202
- - tasks/compile.rake
203
- - tasks/rspec.rake
204
- - tasks/vendor_mysql.rake
205
- has_rdoc: true
60
+ - spec/ssl/ca-cert.pem
61
+ - spec/ssl/ca-key.pem
62
+ - spec/ssl/ca.cnf
63
+ - spec/ssl/cert.cnf
64
+ - spec/ssl/client-cert.pem
65
+ - spec/ssl/client-key.pem
66
+ - spec/ssl/client-req.pem
67
+ - spec/ssl/gen_certs.sh
68
+ - spec/ssl/pkcs8-client-key.pem
69
+ - spec/ssl/pkcs8-server-key.pem
70
+ - spec/ssl/server-cert.pem
71
+ - spec/ssl/server-key.pem
72
+ - spec/ssl/server-req.pem
73
+ - spec/test_data
74
+ - support/5072E1F5.asc
75
+ - support/libmysql.def
76
+ - support/mysql_enc_to_ruby.rb
77
+ - support/ruby_enc_to_mysql.rb
206
78
  homepage: http://github.com/brianmario/mysql2
207
- licenses: []
208
-
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
209
82
  post_install_message:
210
- rdoc_options:
211
- - --charset=UTF-8
212
- require_paths:
83
+ rdoc_options:
84
+ - "--charset=UTF-8"
85
+ require_paths:
213
86
  - lib
214
- required_ruby_version: !ruby/object:Gem::Requirement
215
- none: false
216
- requirements:
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
217
89
  - - ">="
218
- - !ruby/object:Gem::Version
219
- hash: 3
220
- segments:
221
- - 0
222
- version: "0"
223
- required_rubygems_version: !ruby/object:Gem::Requirement
224
- none: false
225
- requirements:
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
226
94
  - - ">="
227
- - !ruby/object:Gem::Version
228
- hash: 3
229
- segments:
230
- - 0
231
- version: "0"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
232
97
  requirements: []
233
-
234
98
  rubyforge_project:
235
- rubygems_version: 1.6.2
99
+ rubygems_version: 2.5.2
236
100
  signing_key:
237
- specification_version: 3
101
+ specification_version: 4
238
102
  summary: A simple, fast Mysql library for Ruby, binding to libmysql
239
- test_files:
103
+ test_files:
240
104
  - examples/eventmachine.rb
241
105
  - examples/threaded.rb
106
+ - spec/configuration.yml.example
242
107
  - spec/em/em_spec.rb
108
+ - spec/my.cnf.example
243
109
  - spec/mysql2/client_spec.rb
244
110
  - spec/mysql2/error_spec.rb
245
111
  - spec/mysql2/result_spec.rb
112
+ - spec/mysql2/statement_spec.rb
246
113
  - spec/rcov.opts
247
114
  - spec/spec_helper.rb
115
+ - spec/ssl/ca-cert.pem
116
+ - spec/ssl/ca-key.pem
117
+ - spec/ssl/ca.cnf
118
+ - spec/ssl/cert.cnf
119
+ - spec/ssl/client-cert.pem
120
+ - spec/ssl/client-key.pem
121
+ - spec/ssl/client-req.pem
122
+ - spec/ssl/gen_certs.sh
123
+ - spec/ssl/pkcs8-client-key.pem
124
+ - spec/ssl/pkcs8-server-key.pem
125
+ - spec/ssl/server-cert.pem
126
+ - spec/ssl/server-key.pem
127
+ - spec/ssl/server-req.pem
128
+ - spec/test_data
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- Makefile
2
- *.dSYM
3
- *.o
4
- *.bundle
5
- *.so
6
- *.a
7
- *.rbc
8
- mkmf.log
9
- pkg/
10
- tmp
11
- vendor
12
- lib/mysql2/mysql2.rb
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --colour
3
- --fail-fast
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 1.9.3@mysql2 --create
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
5
- - ree
6
- before_script:
7
- - "mysql -e 'create database test;' >/dev/null"
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2010-2011 Brian Lopez - http://github.com/brianmario
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,5 +0,0 @@
1
- # encoding: UTF-8
2
- require 'rake'
3
-
4
- # Load custom tasks
5
- Dir['tasks/*.rake'].sort.each { |f| load f }
@@ -1,51 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- require 'rubygems'
5
- require 'benchmark'
6
- require 'active_record'
7
-
8
- ActiveRecord::Base.default_timezone = :local
9
- ActiveRecord::Base.time_zone_aware_attributes = true
10
-
11
- number_of = 10
12
- mysql2_opts = {
13
- :adapter => 'mysql2',
14
- :database => 'test'
15
- }
16
- mysql_opts = {
17
- :adapter => 'mysql',
18
- :database => 'test'
19
- }
20
-
21
- class Mysql2Model < ActiveRecord::Base
22
- set_table_name :mysql2_test
23
- end
24
-
25
- class MysqlModel < ActiveRecord::Base
26
- set_table_name :mysql2_test
27
- end
28
-
29
- Benchmark.bmbm do |x|
30
- x.report "Mysql2" do
31
- Mysql2Model.establish_connection(mysql2_opts)
32
- number_of.times do
33
- Mysql2Model.all(:limit => 1000).each{ |r|
34
- r.attributes.keys.each{ |k|
35
- r.send(k.to_sym)
36
- }
37
- }
38
- end
39
- end
40
-
41
- x.report "Mysql" do
42
- MysqlModel.establish_connection(mysql_opts)
43
- number_of.times do
44
- MysqlModel.all(:limit => 1000).each{ |r|
45
- r.attributes.keys.each{ |k|
46
- r.send(k.to_sym)
47
- }
48
- }
49
- end
50
- end
51
- end
@@ -1,42 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- require 'rubygems'
5
- require 'benchmark'
6
- require 'active_record'
7
-
8
- times = 25
9
-
10
-
11
- # mysql2
12
- mysql2_opts = {
13
- :adapter => 'mysql2',
14
- :database => 'test',
15
- :pool => times
16
- }
17
- ActiveRecord::Base.establish_connection(mysql2_opts)
18
- x = Benchmark.realtime do
19
- threads = []
20
- times.times do
21
- threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
22
- end
23
- threads.each {|t| t.join }
24
- end
25
- puts "mysql2: #{x} seconds"
26
-
27
-
28
- # mysql
29
- mysql2_opts = {
30
- :adapter => 'mysql',
31
- :database => 'test',
32
- :pool => times
33
- }
34
- ActiveRecord::Base.establish_connection(mysql2_opts)
35
- x = Benchmark.realtime do
36
- threads = []
37
- times.times do
38
- threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
39
- end
40
- threads.each {|t| t.join }
41
- end
42
- puts "mysql: #{x} seconds"
@@ -1,33 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- raise Mysql2::Mysql2Error.new("GC allocation benchmarks only supported on Ruby 1.9!") unless RUBY_VERSION =~ /1\.9/
5
-
6
- require 'rubygems'
7
- require 'benchmark'
8
- require 'active_record'
9
-
10
- ActiveRecord::Base.default_timezone = :local
11
- ActiveRecord::Base.time_zone_aware_attributes = true
12
-
13
- class Mysql2Model < ActiveRecord::Base
14
- set_table_name :mysql2_test
15
- end
16
-
17
- def bench_allocations(feature, iterations = 10, &blk)
18
- puts "GC overhead for #{feature}"
19
- Mysql2Model.establish_connection(:adapter => 'mysql2', :database => 'test')
20
- GC::Profiler.clear
21
- GC::Profiler.enable
22
- iterations.times{ blk.call }
23
- GC::Profiler.report(STDOUT)
24
- GC::Profiler.disable
25
- end
26
-
27
- bench_allocations('coercion') do
28
- Mysql2Model.all(:limit => 1000).each{ |r|
29
- r.attributes.keys.each{ |k|
30
- r.send(k.to_sym)
31
- }
32
- }
33
- end
data/benchmark/escape.rb DELETED
@@ -1,36 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- require 'rubygems'
5
- require 'benchmark'
6
- require 'mysql'
7
- require 'mysql2'
8
- require 'do_mysql'
9
-
10
- def run_escape_benchmarks(str, number_of = 1000)
11
- Benchmark.bmbm do |x|
12
- mysql = Mysql.new("localhost", "root")
13
- x.report "Mysql #{str.inspect}" do
14
- number_of.times do
15
- mysql.quote str
16
- end
17
- end
18
-
19
- mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
20
- x.report "Mysql2 #{str.inspect}" do
21
- number_of.times do
22
- mysql2.escape str
23
- end
24
- end
25
-
26
- do_mysql = DataObjects::Connection.new("mysql://localhost/test")
27
- x.report "do_mysql #{str.inspect}" do
28
- number_of.times do
29
- do_mysql.quote_string str
30
- end
31
- end
32
- end
33
- end
34
-
35
- run_escape_benchmarks "abc'def\"ghi\0jkl%mno"
36
- run_escape_benchmarks "clean string"