-
Notifications
You must be signed in to change notification settings - Fork 5
/
integration_benchmark_test.go.erb
71 lines (66 loc) · 2.44 KB
/
integration_benchmark_test.go.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Code generated by erb. DO NOT EDIT.
package decimal_test
import (
"context"
"testing"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5"
"github.com/shopspring/decimal"
pgxdecimal "github.com/jackc/pgx-shopspring-decimal"
)
<%
[
["numeric", ["int64", "float64", "pgtype.Numeric", "decimal.Decimal", "decimal.NullDecimal", "pgxdecimal.Decimal", "pgxdecimal.NullDecimal"], [[1, 1], [1, 10], [10, 1], [100, 10]]],
].each do |pg_type, go_types, rows_columns|
%>
<% go_types.each do |go_type| %>
<% rows_columns.each do |rows, columns| %>
func BenchmarkQueryDecode_PG_<%= pg_type %>_to_Go_<%= go_type.gsub(/\W/, "_") %>_<%= rows %>_rows_<%= columns %>_columns(b *testing.B) {
defaultConnTestRunner.RunTest(context.Background(), b, func(ctx context.Context, _ testing.TB, conn *pgx.Conn) {
b.ResetTimer()
var v [<%= columns %>]<%= go_type %>
for i := 0; i < b.N; i++ {
_, err := conn.QueryFunc(
ctx,
`select <% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>n::<%= pg_type %> + <%= col_idx%><% end %> from generate_series(1, <%= rows %>) n`,
nil,
[]interface{}{<% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>&v[<%= col_idx%>]<% end %>},
func(pgx.QueryFuncRow) error { return nil },
)
if err != nil {
b.Fatal(err)
}
}
})
}
<% end %>
<% end %>
<% end %>
<%
[
["numeric", ["decimal.Decimal", "decimal.NullDecimal"], [[1, 1], [1, 10], [10, 1], [100, 10]]],
].each do |pg_type, go_types, rows_columns|
%>
<% go_types.each do |go_type| %>
<% rows_columns.each do |rows, columns| %>
func BenchmarkQueryDecode_PG_<%= pg_type %>_to_Go_<%= go_type.gsub(/\W/, "_") %>_<%= rows %>_rows_<%= columns %>_columns_with_Register(b *testing.B) {
defaultConnTestRunner.RunTest(context.Background(), b, func(ctx context.Context, _ testing.TB, conn *pgx.Conn) {
b.ResetTimer()
var v [<%= columns %>]<%= go_type %>
for i := 0; i < b.N; i++ {
_, err := conn.QueryFunc(
context.Background(),
`select <% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>n::<%= pg_type %> + <%= col_idx%><% end %> from generate_series(1, <%= rows %>) n`,
nil,
[]interface{}{<% columns.times do |col_idx| %><% if col_idx != 0 %>, <% end %>&v[<%= col_idx%>]<% end %>},
func(pgx.QueryFuncRow) error { return nil },
)
if err != nil {
b.Fatal(err)
}
}
})
}
<% end %>
<% end %>
<% end %>