@@ -46,9 +46,13 @@ func (tb *TB) checkStmt(stmt *sql.Stmt, err error) *sql.Stmt {
46
46
return stmt
47
47
}
48
48
49
- func initDB (b * testing.B , queries ... string ) * sql.DB {
49
+ func initDB (b * testing.B , useCompression bool , queries ... string ) * sql.DB {
50
50
tb := (* TB )(b )
51
- db := tb .checkDB (sql .Open (driverNameTest , dsn ))
51
+ comprStr := ""
52
+ if useCompression {
53
+ comprStr = "&compress=1"
54
+ }
55
+ db := tb .checkDB (sql .Open (driverNameTest , dsn + comprStr ))
52
56
for _ , query := range queries {
53
57
if _ , err := db .Exec (query ); err != nil {
54
58
b .Fatalf ("error on %q: %v" , query , err )
@@ -60,10 +64,18 @@ func initDB(b *testing.B, queries ...string) *sql.DB {
60
64
const concurrencyLevel = 10
61
65
62
66
func BenchmarkQuery (b * testing.B ) {
67
+ benchmarkQueryHelper (b , false )
68
+ }
69
+
70
+ func BenchmarkQueryCompression (b * testing.B ) {
71
+ benchmarkQueryHelper (b , true )
72
+ }
73
+
74
+ func benchmarkQueryHelper (b * testing.B , compr bool ) {
63
75
tb := (* TB )(b )
64
76
b .StopTimer ()
65
77
b .ReportAllocs ()
66
- db := initDB (b ,
78
+ db := initDB (b , compr ,
67
79
"DROP TABLE IF EXISTS foo" ,
68
80
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))" ,
69
81
`INSERT INTO foo VALUES (1, "one")` ,
@@ -222,7 +234,7 @@ func BenchmarkInterpolation(b *testing.B) {
222
234
},
223
235
maxAllowedPacket : maxPacketSize ,
224
236
maxWriteSize : maxPacketSize - 1 ,
225
- buf : newBuffer (nil ),
237
+ buf : newBuffer (),
226
238
}
227
239
228
240
args := []driver.Value {
@@ -269,7 +281,7 @@ func benchmarkQueryContext(b *testing.B, db *sql.DB, p int) {
269
281
}
270
282
271
283
func BenchmarkQueryContext (b * testing.B ) {
272
- db := initDB (b ,
284
+ db := initDB (b , false ,
273
285
"DROP TABLE IF EXISTS foo" ,
274
286
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))" ,
275
287
`INSERT INTO foo VALUES (1, "one")` ,
@@ -305,7 +317,7 @@ func benchmarkExecContext(b *testing.B, db *sql.DB, p int) {
305
317
}
306
318
307
319
func BenchmarkExecContext (b * testing.B ) {
308
- db := initDB (b ,
320
+ db := initDB (b , false ,
309
321
"DROP TABLE IF EXISTS foo" ,
310
322
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))" ,
311
323
`INSERT INTO foo VALUES (1, "one")` ,
@@ -323,7 +335,7 @@ func BenchmarkExecContext(b *testing.B) {
323
335
// "size=" means size of each blobs.
324
336
func BenchmarkQueryRawBytes (b * testing.B ) {
325
337
var sizes []int = []int {100 , 1000 , 2000 , 4000 , 8000 , 12000 , 16000 , 32000 , 64000 , 256000 }
326
- db := initDB (b ,
338
+ db := initDB (b , false ,
327
339
"DROP TABLE IF EXISTS bench_rawbytes" ,
328
340
"CREATE TABLE bench_rawbytes (id INT PRIMARY KEY, val LONGBLOB)" ,
329
341
)
@@ -376,7 +388,7 @@ func BenchmarkQueryRawBytes(b *testing.B) {
376
388
// BenchmarkReceiveMassiveRows measures performance of receiving large number of rows.
377
389
func BenchmarkReceiveMassiveRows (b * testing.B ) {
378
390
// Setup -- prepare 10000 rows.
379
- db := initDB (b ,
391
+ db := initDB (b , false ,
380
392
"DROP TABLE IF EXISTS foo" ,
381
393
"CREATE TABLE foo (id INT PRIMARY KEY, val TEXT)" )
382
394
defer db .Close ()
0 commit comments