@@ -46,9 +46,13 @@ func (tb *TB) checkStmt(stmt *sql.Stmt, err error) *sql.Stmt {
4646 return stmt
4747}
4848
49- func initDB (b * testing.B , queries ... string ) * sql.DB {
49+ func initDB (b * testing.B , useCompression bool , queries ... string ) * sql.DB {
5050 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 ))
5256 for _ , query := range queries {
5357 if _ , err := db .Exec (query ); err != nil {
5458 b .Fatalf ("error on %q: %v" , query , err )
@@ -60,10 +64,18 @@ func initDB(b *testing.B, queries ...string) *sql.DB {
6064const concurrencyLevel = 10
6165
6266func 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 ) {
6375 tb := (* TB )(b )
6476 b .StopTimer ()
6577 b .ReportAllocs ()
66- db := initDB (b ,
78+ db := initDB (b , compr ,
6779 "DROP TABLE IF EXISTS foo" ,
6880 "CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))" ,
6981 `INSERT INTO foo VALUES (1, "one")` ,
@@ -222,7 +234,7 @@ func BenchmarkInterpolation(b *testing.B) {
222234 },
223235 maxAllowedPacket : maxPacketSize ,
224236 maxWriteSize : maxPacketSize - 1 ,
225- buf : newBuffer (nil ),
237+ buf : newBuffer (),
226238 }
227239
228240 args := []driver.Value {
@@ -269,7 +281,7 @@ func benchmarkQueryContext(b *testing.B, db *sql.DB, p int) {
269281}
270282
271283func BenchmarkQueryContext (b * testing.B ) {
272- db := initDB (b ,
284+ db := initDB (b , false ,
273285 "DROP TABLE IF EXISTS foo" ,
274286 "CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))" ,
275287 `INSERT INTO foo VALUES (1, "one")` ,
@@ -305,7 +317,7 @@ func benchmarkExecContext(b *testing.B, db *sql.DB, p int) {
305317}
306318
307319func BenchmarkExecContext (b * testing.B ) {
308- db := initDB (b ,
320+ db := initDB (b , false ,
309321 "DROP TABLE IF EXISTS foo" ,
310322 "CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))" ,
311323 `INSERT INTO foo VALUES (1, "one")` ,
@@ -323,7 +335,7 @@ func BenchmarkExecContext(b *testing.B) {
323335// "size=" means size of each blobs.
324336func BenchmarkQueryRawBytes (b * testing.B ) {
325337 var sizes []int = []int {100 , 1000 , 2000 , 4000 , 8000 , 12000 , 16000 , 32000 , 64000 , 256000 }
326- db := initDB (b ,
338+ db := initDB (b , false ,
327339 "DROP TABLE IF EXISTS bench_rawbytes" ,
328340 "CREATE TABLE bench_rawbytes (id INT PRIMARY KEY, val LONGBLOB)" ,
329341 )
@@ -376,7 +388,7 @@ func BenchmarkQueryRawBytes(b *testing.B) {
376388// BenchmarkReceiveMassiveRows measures performance of receiving large number of rows.
377389func BenchmarkReceiveMassiveRows (b * testing.B ) {
378390 // Setup -- prepare 10000 rows.
379- db := initDB (b ,
391+ db := initDB (b , false ,
380392 "DROP TABLE IF EXISTS foo" ,
381393 "CREATE TABLE foo (id INT PRIMARY KEY, val TEXT)" )
382394 defer db .Close ()
0 commit comments