File: escape.rb

package info (click to toggle)
ruby-mysql2 0.5.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,096 kB
  • sloc: ansic: 3,459; ruby: 3,334; sh: 226; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (3)
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"