File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ package mysql
2
+
3
+ import (
4
+ "database/sql"
5
+ "strings"
6
+ "testing"
7
+ )
8
+
9
+ var (
10
+ // dsn from driver_test.go
11
+ sample = []byte (strings .Repeat ("0123456789abcdef" , 1024 * 1024 ))
12
+ )
13
+
14
+ func BenchmarkRoundtripText (b * testing.B ) {
15
+ db , err := sql .Open ("mysql" , dsn )
16
+ if err != nil {
17
+ b .Fatalf ("crashed" )
18
+ }
19
+ var result string
20
+ for i := 0 ; i < b .N ; i ++ {
21
+ length := 16 + i % (4 * b .N )
22
+ test := string (sample [0 :length ])
23
+ rows , err := db .Query ("SELECT \" " + test + "\" " )
24
+ if err != nil {
25
+ b .Fatalf ("crashed" )
26
+ }
27
+ if ! rows .Next () {
28
+ rows .Close ()
29
+ b .Fatalf ("crashed" )
30
+ }
31
+ err = rows .Scan (& result )
32
+ if err != nil {
33
+ rows .Close ()
34
+ b .Fatalf ("crashed" )
35
+ }
36
+ if result != test {
37
+ rows .Close ()
38
+ b .Errorf ("mismatch" )
39
+ }
40
+ rows .Close ()
41
+ }
42
+ }
43
+
44
+ func BenchmarkRoundtripPrepared (b * testing.B ) {
45
+ db , err := sql .Open ("mysql" , dsn )
46
+ if err != nil {
47
+ b .Fatalf ("crashed" )
48
+ }
49
+ var result string
50
+ stmt , err := db .Prepare ("SELECT ?" )
51
+ if err != nil {
52
+ b .Fatalf ("crashed" )
53
+ }
54
+ for i := 0 ; i < b .N ; i ++ {
55
+ length := 16 + i % (4 * b .N )
56
+ test := string (sample [0 :length ])
57
+ rows , err := stmt .Query (test )
58
+ if err != nil {
59
+ b .Fatalf ("crashed" )
60
+ }
61
+ if ! rows .Next () {
62
+ rows .Close ()
63
+ b .Fatalf ("crashed" )
64
+ }
65
+ err = rows .Scan (& result )
66
+ if err != nil {
67
+ rows .Close ()
68
+ b .Fatalf ("crashed" )
69
+ }
70
+ if result != test {
71
+ rows .Close ()
72
+ b .Errorf ("mismatch" )
73
+ }
74
+ rows .Close ()
75
+ }
76
+ }
You can’t perform that action at this time.
0 commit comments