diff --git a/pgtype/integration_benchmark_test.go b/pgtype/integration_benchmark_test.go index cca6dd1e..0ee87ba3 100644 --- a/pgtype/integration_benchmark_test.go +++ b/pgtype/integration_benchmark_test.go @@ -1290,3 +1290,279 @@ func BenchmarkQueryBinaryFormatDecode_PG_numeric_to_Go_pgtype_Numeric_100_rows_1 } } } + +func BenchmarkQueryTextFormatDecode_PG_Int4Array_With_Go_Int4Array_10(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 10) n`, + []interface{}{pgx.QueryResultFormats{pgx.TextFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryTextFormatDecode_PG_Int4Array_With_Go_ArrayType_10(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + conn.ConnInfo().RegisterDataType(pgtype.DataType{ + Value: pgtype.NewArrayType("_int4", pgtype.Int4OID, func() pgtype.ValueTranscoder { return &pgtype.Int4{} }), + Name: "_int4", + OID: pgtype.Int4ArrayOID, + }) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 10) n`, + []interface{}{pgx.QueryResultFormats{pgx.TextFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryBinaryFormatDecode_PG_Int4Array_With_Go_Int4Array_10(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 10) n`, + []interface{}{pgx.QueryResultFormats{pgx.BinaryFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryBinaryFormatDecode_PG_Int4Array_With_Go_ArrayType_10(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + conn.ConnInfo().RegisterDataType(pgtype.DataType{ + Value: pgtype.NewArrayType("_int4", pgtype.Int4OID, func() pgtype.ValueTranscoder { return &pgtype.Int4{} }), + Name: "_int4", + OID: pgtype.Int4ArrayOID, + }) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 10) n`, + []interface{}{pgx.QueryResultFormats{pgx.BinaryFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryTextFormatDecode_PG_Int4Array_With_Go_Int4Array_100(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 100) n`, + []interface{}{pgx.QueryResultFormats{pgx.TextFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryTextFormatDecode_PG_Int4Array_With_Go_ArrayType_100(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + conn.ConnInfo().RegisterDataType(pgtype.DataType{ + Value: pgtype.NewArrayType("_int4", pgtype.Int4OID, func() pgtype.ValueTranscoder { return &pgtype.Int4{} }), + Name: "_int4", + OID: pgtype.Int4ArrayOID, + }) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 100) n`, + []interface{}{pgx.QueryResultFormats{pgx.TextFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryBinaryFormatDecode_PG_Int4Array_With_Go_Int4Array_100(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 100) n`, + []interface{}{pgx.QueryResultFormats{pgx.BinaryFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryBinaryFormatDecode_PG_Int4Array_With_Go_ArrayType_100(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + conn.ConnInfo().RegisterDataType(pgtype.DataType{ + Value: pgtype.NewArrayType("_int4", pgtype.Int4OID, func() pgtype.ValueTranscoder { return &pgtype.Int4{} }), + Name: "_int4", + OID: pgtype.Int4ArrayOID, + }) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 100) n`, + []interface{}{pgx.QueryResultFormats{pgx.BinaryFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryTextFormatDecode_PG_Int4Array_With_Go_Int4Array_1000(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 1000) n`, + []interface{}{pgx.QueryResultFormats{pgx.TextFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryTextFormatDecode_PG_Int4Array_With_Go_ArrayType_1000(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + conn.ConnInfo().RegisterDataType(pgtype.DataType{ + Value: pgtype.NewArrayType("_int4", pgtype.Int4OID, func() pgtype.ValueTranscoder { return &pgtype.Int4{} }), + Name: "_int4", + OID: pgtype.Int4ArrayOID, + }) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 1000) n`, + []interface{}{pgx.QueryResultFormats{pgx.TextFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryBinaryFormatDecode_PG_Int4Array_With_Go_Int4Array_1000(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 1000) n`, + []interface{}{pgx.QueryResultFormats{pgx.BinaryFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQueryBinaryFormatDecode_PG_Int4Array_With_Go_ArrayType_1000(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + conn.ConnInfo().RegisterDataType(pgtype.DataType{ + Value: pgtype.NewArrayType("_int4", pgtype.Int4OID, func() pgtype.ValueTranscoder { return &pgtype.Int4{} }), + Name: "_int4", + OID: pgtype.Int4ArrayOID, + }) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, 1000) n`, + []interface{}{pgx.QueryResultFormats{pgx.BinaryFormatCode}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} diff --git a/pgtype/integration_benchmark_test.go.erb b/pgtype/integration_benchmark_test.go.erb index 761087b7..f642e6ca 100644 --- a/pgtype/integration_benchmark_test.go.erb +++ b/pgtype/integration_benchmark_test.go.erb @@ -42,3 +42,53 @@ func BenchmarkQuery<%= format_name %>FormatDecode_PG_<%= pg_type %>_to_Go_<%= go <% end %> <% end %> <% end %> + +<% [10, 100, 1000].each do |array_size| %> +<% [["Text", "pgx.TextFormatCode"], ["Binary", "pgx.BinaryFormatCode"]].each do |format_name, format_code| %> +func BenchmarkQuery<%= format_name %>FormatDecode_PG_Int4Array_With_Go_Int4Array_<%= array_size %>(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, <%= array_size %>) n`, + []interface{}{pgx.QueryResultFormats{<%= format_code %>}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkQuery<%= format_name %>FormatDecode_PG_Int4Array_With_Go_ArrayType_<%= array_size %>(b *testing.B) { + conn := testutil.MustConnectPgx(b) + defer testutil.MustCloseContext(b, conn) + + conn.ConnInfo().RegisterDataType(pgtype.DataType{ + Value: pgtype.NewArrayType("_int4", pgtype.Int4OID, func() pgtype.ValueTranscoder { return &pgtype.Int4{} }), + Name: "_int4", + OID: pgtype.Int4ArrayOID, + }) + + b.ResetTimer() + var v []int32 + for i := 0; i < b.N; i++ { + _, err := conn.QueryFunc( + context.Background(), + `select array_agg(n) from generate_series(1, <%= array_size %>) n`, + []interface{}{pgx.QueryResultFormats{<%= format_code %>}}, + []interface{}{&v}, + func(pgx.QueryFuncRow) error { return nil }, + ) + if err != nil { + b.Fatal(err) + } + } +} +<% end %> +<% end %>