MCPcopy
hub / github.com/jackc/pgx / BenchmarkSelectRowsPgConnExecStatement

Function BenchmarkSelectRowsPgConnExecStatement

bench_test.go:1301–1344  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1299}
1300
1301func BenchmarkSelectRowsPgConnExecStatement(b *testing.B) {
1302 conn := mustConnectString(b, os.Getenv("PGX_TEST_DATABASE"))
1303 defer closeConn(b, conn)
1304
1305 rowCounts := getSelectRowsCounts(b)
1306
1307 psd, err := conn.PgConn().Prepare(context.Background(), "ps1", "select n, 'Adam', 'Smith ' || n, 'male', '1952-06-16'::date, 258, 72, '{foo,bar,baz}'::text[], '2001-01-28 01:02:03-05'::timestamptz from generate_series(100001, 100000 + $1) n", nil)
1308 if err != nil {
1309 b.Fatal(err)
1310 }
1311
1312 for _, rowCount := range rowCounts {
1313 b.Run(fmt.Sprintf("%d rows", rowCount), func(b *testing.B) {
1314 formats := []struct {
1315 name string
1316 code int16
1317 }{
1318 {"text", pgx.TextFormatCode},
1319 {"binary - mostly", pgx.BinaryFormatCode},
1320 }
1321 for _, format := range formats {
1322 b.Run(format.name, func(b *testing.B) {
1323 for i := 0; i < b.N; i++ {
1324 rr := conn.PgConn().ExecStatement(
1325 context.Background(),
1326 psd,
1327 [][]byte{[]byte(strconv.FormatInt(rowCount, 10))},
1328 nil,
1329 []int16{format.code, pgx.TextFormatCode, pgx.TextFormatCode, pgx.TextFormatCode, format.code, format.code, format.code, format.code, format.code},
1330 )
1331 for rr.NextRow() {
1332 rr.Values()
1333 }
1334
1335 _, err := rr.Close()
1336 if err != nil {
1337 b.Fatal(err)
1338 }
1339 }
1340 })
1341 }
1342 })
1343 }
1344}
1345
1346type queryRecorder struct {
1347 conn net.Conn

Callers

nothing calls this directly

Calls 10

mustConnectStringFunction · 0.85
PgConnMethod · 0.80
NextRowMethod · 0.80
closeConnFunction · 0.70
getSelectRowsCountsFunction · 0.70
PrepareMethod · 0.65
ValuesMethod · 0.65
CloseMethod · 0.65
RunMethod · 0.45
ExecStatementMethod · 0.45

Tested by

no test coverage detected