MCPcopy
hub / github.com/go-sql-driver/mysql / benchmarkQuery

Function benchmarkQuery

benchmark_test.go:74–113  ·  view source on GitHub ↗
(b *testing.B, compr bool)

Source from the content-addressed store, hash-verified

72}
73
74func benchmarkQuery(b *testing.B, compr bool) {
75 tb := (*TB)(b)
76 b.ReportAllocs()
77 db := initDB(b, compr,
78 "DROP TABLE IF EXISTS foo",
79 "CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))",
80 `INSERT INTO foo VALUES (1, "one")`,
81 `INSERT INTO foo VALUES (2, "two")`,
82 )
83 db.SetMaxIdleConns(concurrencyLevel)
84 defer db.Close()
85
86 stmt := tb.checkStmt(db.Prepare("SELECT val FROM foo WHERE id=?"))
87 defer stmt.Close()
88
89 remain := int64(b.N)
90 var wg sync.WaitGroup
91 wg.Add(concurrencyLevel)
92 defer wg.Wait()
93 b.StartTimer()
94
95 for range concurrencyLevel {
96 go func() {
97 for {
98 if atomic.AddInt64(&remain, -1) < 0 {
99 wg.Done()
100 return
101 }
102
103 var got string
104 tb.check(stmt.QueryRow(1).Scan(&got))
105 if got != "one" {
106 b.Errorf("query = %q; want one", got)
107 wg.Done()
108 return
109 }
110 }
111 }()
112 }
113}
114
115func BenchmarkExec(b *testing.B) {
116 tb := (*TB)(b)

Callers 2

BenchmarkQueryFunction · 0.85
BenchmarkQueryCompressedFunction · 0.85

Calls 6

initDBFunction · 0.85
checkStmtMethod · 0.80
PrepareMethod · 0.80
checkMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected