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

Function benchmarkQueryContext

benchmark_test.go:259–280  ·  view source on GitHub ↗
(b *testing.B, db *sql.DB, p int)

Source from the content-addressed store, hash-verified

257}
258
259func benchmarkQueryContext(b *testing.B, db *sql.DB, p int) {
260 ctx, cancel := context.WithCancel(context.Background())
261 defer cancel()
262 db.SetMaxIdleConns(p * runtime.GOMAXPROCS(0))
263
264 tb := (*TB)(b)
265 stmt := tb.checkStmt(db.PrepareContext(ctx, "SELECT val FROM foo WHERE id=?"))
266 defer stmt.Close()
267
268 b.SetParallelism(p)
269 b.ReportAllocs()
270 b.ResetTimer()
271 b.RunParallel(func(pb *testing.PB) {
272 var got string
273 for pb.Next() {
274 tb.check(stmt.QueryRow(1).Scan(&got))
275 if got != "one" {
276 b.Fatalf("query = %q; want one", got)
277 }
278 }
279 })
280}
281
282func BenchmarkQueryContext(b *testing.B) {
283 db := initDB(b, false,

Callers 1

BenchmarkQueryContextFunction · 0.85

Calls 6

checkStmtMethod · 0.80
PrepareContextMethod · 0.80
checkMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected