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

Function BenchmarkMinimalPreparedSelect

pgxpool/bench_test.go:57–81  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

55}
56
57func BenchmarkMinimalPreparedSelect(b *testing.B) {
58 config, err := pgxpool.ParseConfig(os.Getenv("PGX_TEST_DATABASE"))
59 require.NoError(b, err)
60
61 config.AfterConnect = func(ctx context.Context, c *pgx.Conn) error {
62 _, err := c.Prepare(ctx, "ps1", "select $1::int8")
63 return err
64 }
65
66 db, err := pgxpool.NewWithConfig(context.Background(), config)
67 require.NoError(b, err)
68
69 var n int64
70
71 for i := 0; b.Loop(); i++ {
72 err = db.QueryRow(context.Background(), "ps1", i).Scan(&n)
73 if err != nil {
74 b.Fatal(err)
75 }
76
77 if n != int64(i) {
78 b.Fatalf("expected %d, got %d", i, n)
79 }
80 }
81}

Callers

nothing calls this directly

Calls 5

ParseConfigFunction · 0.92
NewWithConfigFunction · 0.92
PrepareMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected