(b *testing.B)
| 38 | } |
| 39 | |
| 40 | func BenchmarkExec(b *testing.B) { |
| 41 | expectedValues := [][]byte{[]byte("hello"), []byte("42"), []byte("2019-01-01")} |
| 42 | benchmarks := []struct { |
| 43 | name string |
| 44 | ctx context.Context |
| 45 | }{ |
| 46 | // Using an empty context other than context.Background() to compare |
| 47 | // performance |
| 48 | {"background context", context.Background()}, |
| 49 | {"empty context", context.TODO()}, |
| 50 | } |
| 51 | |
| 52 | for _, bm := range benchmarks { |
| 53 | b.Run(bm.name, func(b *testing.B) { |
| 54 | conn, err := pgconn.Connect(bm.ctx, os.Getenv("PGX_TEST_DATABASE")) |
| 55 | require.Nil(b, err) |
| 56 | defer closeConn(b, conn) |
| 57 | |
| 58 | b.ResetTimer() |
| 59 | |
| 60 | for b.Loop() { |
| 61 | mrr := conn.Exec(bm.ctx, "select 'hello'::text as a, 42::int4 as b, '2019-01-01'::date") |
| 62 | |
| 63 | for mrr.NextResult() { |
| 64 | rr := mrr.ResultReader() |
| 65 | |
| 66 | rowCount := 0 |
| 67 | for rr.NextRow() { |
| 68 | rowCount++ |
| 69 | if len(rr.Values()) != len(expectedValues) { |
| 70 | b.Fatalf("unexpected number of values: %d", len(rr.Values())) |
| 71 | } |
| 72 | for i := range rr.Values() { |
| 73 | if !bytes.Equal(rr.Values()[i], expectedValues[i]) { |
| 74 | b.Fatalf("unexpected values: %s %s", rr.Values()[i], expectedValues[i]) |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | _, err = rr.Close() |
| 79 | if err != nil { |
| 80 | b.Fatal(err) |
| 81 | } |
| 82 | if rowCount != 1 { |
| 83 | b.Fatalf("unexpected rowCount: %d", rowCount) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | err := mrr.Close() |
| 88 | if err != nil { |
| 89 | b.Fatal(err) |
| 90 | } |
| 91 | } |
| 92 | }) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | func BenchmarkExecPossibleToCancel(b *testing.B) { |
| 97 | conn, err := pgconn.Connect(context.Background(), os.Getenv("PGX_TEST_DATABASE")) |
nothing calls this directly
no test coverage detected