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

Function BenchmarkSelectRowsPgConnExecParams

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

Source from the content-addressed store, hash-verified

1119}
1120
1121func BenchmarkSelectRowsPgConnExecParams(b *testing.B) {
1122 conn := mustConnectString(b, os.Getenv("PGX_TEST_DATABASE"))
1123 defer closeConn(b, conn)
1124
1125 rowCounts := getSelectRowsCounts(b)
1126
1127 for _, rowCount := range rowCounts {
1128 b.Run(fmt.Sprintf("%d rows", rowCount), func(b *testing.B) {
1129 formats := []struct {
1130 name string
1131 code int16
1132 }{
1133 {"text", pgx.TextFormatCode},
1134 {"binary - mostly", pgx.BinaryFormatCode},
1135 }
1136 for _, format := range formats {
1137 b.Run(format.name, func(b *testing.B) {
1138 for b.Loop() {
1139 rr := conn.PgConn().ExecParams(
1140 context.Background(),
1141 "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",
1142 [][]byte{[]byte(strconv.FormatInt(rowCount, 10))},
1143 nil,
1144 nil,
1145 []int16{format.code, pgx.TextFormatCode, pgx.TextFormatCode, pgx.TextFormatCode, format.code, format.code, format.code, format.code, format.code},
1146 )
1147 for rr.NextRow() {
1148 rr.Values()
1149 }
1150
1151 _, err := rr.Close()
1152 if err != nil {
1153 b.Fatal(err)
1154 }
1155 }
1156 })
1157 }
1158 })
1159 }
1160}
1161
1162func BenchmarkSelectRowsSimpleCollectRowsRowToStructByPos(b *testing.B) {
1163 conn := mustConnectString(b, os.Getenv("PGX_TEST_DATABASE"))

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected