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

Function BenchmarkMinimalPgConnPreparedSelect

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

Source from the content-addressed store, hash-verified

125}
126
127func BenchmarkMinimalPgConnPreparedSelect(b *testing.B) {
128 conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))
129 defer closeConn(b, conn)
130
131 pgConn := conn.PgConn()
132
133 _, err := pgConn.Prepare(context.Background(), "ps1", "select $1::int8", nil)
134 if err != nil {
135 b.Fatal(err)
136 }
137
138 encodedBytes := make([]byte, 8)
139
140 for b.Loop() {
141
142 rr := pgConn.ExecPrepared(context.Background(), "ps1", [][]byte{encodedBytes}, []int16{1}, []int16{1})
143 if err != nil {
144 b.Fatal(err)
145 }
146
147 for rr.NextRow() {
148 for i := range rr.Values() {
149 if !bytes.Equal(rr.Values()[0], encodedBytes) {
150 b.Fatalf("unexpected values: %s %s", rr.Values()[i], encodedBytes)
151 }
152 }
153 }
154 _, err = rr.Close()
155 if err != nil {
156 b.Fatal(err)
157 }
158 }
159}
160
161func BenchmarkMinimalPgConnPreparedStatementDescriptionSelect(b *testing.B) {
162 conn := mustConnect(b, mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")))

Callers

nothing calls this directly

Calls 9

PgConnMethod · 0.80
NextRowMethod · 0.80
mustConnectFunction · 0.70
mustParseConfigFunction · 0.70
closeConnFunction · 0.70
PrepareMethod · 0.65
ValuesMethod · 0.65
CloseMethod · 0.65
ExecPreparedMethod · 0.45

Tested by

no test coverage detected