(b *testing.B, db *sql.DB, p int)
| 257 | } |
| 258 | |
| 259 | func 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 | |
| 282 | func BenchmarkQueryContext(b *testing.B) { |
| 283 | db := initDB(b, false, |
no test coverage detected