github.com/jackc/pgx/v5@v5.5.5/pgtype/integration_benchmark_test.go.erb (about) 1 package pgtype_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/jackc/pgx/v5/pgtype/testutil" 8 "github.com/jackc/pgx/v5" 9 ) 10 11 <% 12 [ 13 ["int4", ["int16", "int32", "int64", "uint64", "pgtype.Int4"], [[1, 1], [1, 10], [10, 1], [100, 10]]], 14 ["numeric", ["int64", "float64", "pgtype.Numeric"], [[1, 1], [1, 10], [10, 1], [100, 10]]], 15 ].each do |pg_type, go_types, rows_columns| 16 %> 17 <% go_types.each do |go_type| %> 18 <% rows_columns.each do |rows, columns| %> 19 <% [["Text", "pgx.TextFormatCode"], ["Binary", "pgx.BinaryFormatCode"]].each do |format_name, format_code| %> 20 func BenchmarkQuery<%= format_name %>FormatDecode_PG_<%= pg_type %>_to_Go_<%= go_type.gsub(/\W/, "_") %>_<%= rows %>_rows_<%= columns %>_columns(b *testing.B) { 21 defaultConnTestRunner.RunTest(context.Background(), b, func(ctx context.Context, _ testing.TB, conn *pgx.Conn) { 22 b.ResetTimer() 23 var v [<%= columns %>]<%= go_type %> 24 for i := 0; i < b.N; i++ { 25 rows, _ := conn.Query( 26 ctx, 27 `select <% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>n::<%= pg_type %> + <%= col_idx%><% end %> from generate_series(1, <%= rows %>) n`, 28 []any{pgx.QueryResultFormats{<%= format_code %>}}, 29 ) 30 _, err := pgx.ForEachRow(rows, []any{<% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>&v[<%= col_idx%>]<% end %>}, func() error { return nil }) 31 if err != nil { 32 b.Fatal(err) 33 } 34 } 35 }) 36 } 37 <% end %> 38 <% end %> 39 <% end %> 40 <% end %> 41 42 <% [10, 100, 1000].each do |array_size| %> 43 <% [["Text", "pgx.TextFormatCode"], ["Binary", "pgx.BinaryFormatCode"]].each do |format_name, format_code| %> 44 func BenchmarkQuery<%= format_name %>FormatDecode_PG_Int4Array_With_Go_Int4Array_<%= array_size %>(b *testing.B) { 45 defaultConnTestRunner.RunTest(context.Background(), b, func(ctx context.Context, _ testing.TB, conn *pgx.Conn) { 46 b.ResetTimer() 47 var v []int32 48 for i := 0; i < b.N; i++ { 49 rows, _ := conn.Query( 50 ctx, 51 `select array_agg(n) from generate_series(1, <%= array_size %>) n`, 52 []any{pgx.QueryResultFormats{<%= format_code %>}}, 53 ) 54 _, err := pgx.ForEachRow(rows, []any{&v}, func() error { return nil }) 55 if err != nil { 56 b.Fatal(err) 57 } 58 } 59 }) 60 } 61 <% end %> 62 <% end %>