-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
176 lines (168 loc) · 9.71 KB
/
benchmark_test.go
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package mintab
import (
"bytes"
"testing"
)
func BenchmarkMintabInputNoHeader(b *testing.B) {
data := Input{
Header: nil,
Data: [][]any{
{"i-1", "server-1", "running"},
{"i-2", "server-2", "stopped"},
{"i-3", "server-3", "pending"},
{"i-4", "server-4", "terminated"},
{"i-5", "server-5", "stopping"},
{"i-6", "server-6", "shutting-down"},
},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
t := New(&bytes.Buffer{})
if err := t.Load(data); err != nil {
b.Fatal(err)
}
t.Render()
}
}
func BenchmarkMintabInput(b *testing.B) {
data := Input{
Header: []string{"InstanceID", "InstanceName", "InstanceState"},
Data: [][]any{
{"i-1", "server-1", "running"},
{"i-2", "server-2", "stopped"},
{"i-3", "server-3", "pending"},
{"i-4", "server-4", "terminated"},
{"i-5", "server-5", "stopping"},
{"i-6", "server-6", "shutting-down"},
},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
t := New(&bytes.Buffer{})
if err := t.Load(data); err != nil {
b.Fatal(err)
}
t.Render()
}
}
func BenchmarkMintabStruct(b *testing.B) {
data := []struct {
InstanceID string
InstaneceName string
InstanceState string
}{
{InstanceID: "i-1", InstaneceName: "server-1", InstanceState: "running"},
{InstanceID: "i-2", InstaneceName: "server-2", InstanceState: "stopped"},
{InstanceID: "i-3", InstaneceName: "server-3", InstanceState: "pending"},
{InstanceID: "i-4", InstaneceName: "server-4", InstanceState: "terminated"},
{InstanceID: "i-5", InstaneceName: "server-5", InstanceState: "stopping"},
{InstanceID: "i-6", InstaneceName: "server-6", InstanceState: "shutting-down"},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
t := New(&bytes.Buffer{})
if err := t.Load(data); err != nil {
b.Fatal(err)
}
t.Render()
}
}
/*
func BenchmarkMintabInputLarge(b *testing.B) {
data := Input{
Header: []string{
"InstanceID",
"InstanceName",
"VPCID",
"SecurityGroupID",
"FlowDirection",
"IPProtocol",
"FromPort",
"ToPort",
"AddressType",
"CidrBlock",
},
Data: [][]any{
{"i-1", "server-1", "vpc-1", "sg-1", "Ingress", "tcp", 22, 22, "SecurityGroup", "sg-10"},
{"i-1", "server-1", "vpc-1", "sg-1", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-2", "Ingress", "tcp", 443, 443, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-2", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "icmp", -1, -1, "SecurityGroup", "sg-11"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "tcp", 3389, 3389, "Ipv4", "10.1.0.0/16"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "tcp", 0, 65535, "PrefixList", "pl-id/pl-name"},
{"i-2", "server-2", "vpc-1", "sg-3", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-1", "Ingress", "tcp", 22, 22, "SecurityGroup", "sg-10"},
{"i-1", "server-1", "vpc-1", "sg-1", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-2", "Ingress", "tcp", 443, 443, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-2", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "icmp", -1, -1, "SecurityGroup", "sg-11"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "tcp", 3389, 3389, "Ipv4", "10.1.0.0/16"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "tcp", 0, 65535, "PrefixList", "pl-id/pl-name"},
{"i-2", "server-2", "vpc-1", "sg-3", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-1", "Ingress", "tcp", 22, 22, "SecurityGroup", "sg-10"},
{"i-1", "server-1", "vpc-1", "sg-1", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-2", "Ingress", "tcp", 443, 443, "Ipv4", "0.0.0.0/0"},
{"i-1", "server-1", "vpc-1", "sg-2", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "icmp", -1, -1, "SecurityGroup", "sg-11"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "tcp", 3389, 3389, "Ipv4", "10.1.0.0/16"},
{"i-2", "server-2", "vpc-1", "sg-3", "Ingress", "tcp", 0, 65535, "PrefixList", "pl-id/pl-name"},
{"i-2", "server-2", "vpc-1", "sg-3", "Egress", "-1", 0, 0, "Ipv4", "0.0.0.0/0"},
},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
t := New(&bytes.Buffer{}, WithMergeFields([]int{1, 2, 3}))
if err := t.Load(data); err != nil {
b.Fatal(err)
}
t.Render()
}
}
func BenchmarkMintabStructLarge(b *testing.B) {
data := []struct {
InstanceID string
InstanceName string
VPCID string
SecurityGroupID string
FlowDirection string
IPProtocol string
FromPort int
ToPort int
AddressType string
CidrBlock string
}{
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-1", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 22, ToPort: 22, AddressType: "SecurityGroup", CidrBlock: "sg-10"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-1", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-2", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 443, ToPort: 443, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-2", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "icmp", FromPort: -1, ToPort: -1, AddressType: "SecurityGroup", CidrBlock: "sg-11"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 3389, ToPort: 3389, AddressType: "Ipv4", CidrBlock: "10.1.0.0/16"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 0, ToPort: 65535, AddressType: "PrefixList", CidrBlock: "pl-id/pl-name"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-1", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 22, ToPort: 22, AddressType: "SecurityGroup", CidrBlock: "sg-10"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-1", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-2", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 443, ToPort: 443, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-2", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "icmp", FromPort: -1, ToPort: -1, AddressType: "SecurityGroup", CidrBlock: "sg-11"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 3389, ToPort: 3389, AddressType: "Ipv4", CidrBlock: "10.1.0.0/16"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 0, ToPort: 65535, AddressType: "PrefixList", CidrBlock: "pl-id/pl-name"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-1", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 22, ToPort: 22, AddressType: "SecurityGroup", CidrBlock: "sg-10"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-1", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-2", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 443, ToPort: 443, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-1", InstanceName: "server-1", VPCID: "vpc-1", SecurityGroupID: "sg-2", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "icmp", FromPort: -1, ToPort: -1, AddressType: "SecurityGroup", CidrBlock: "sg-11"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 3389, ToPort: 3389, AddressType: "Ipv4", CidrBlock: "10.1.0.0/16"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Ingress", IPProtocol: "tcp", FromPort: 0, ToPort: 65535, AddressType: "PrefixList", CidrBlock: "pl-id/pl-name"},
{InstanceID: "i-2", InstanceName: "server-2", VPCID: "vpc-1", SecurityGroupID: "sg-3", FlowDirection: "Egress", IPProtocol: "-1", FromPort: 0, ToPort: 0, AddressType: "Ipv4", CidrBlock: "0.0.0.0/0"},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
t := New(&bytes.Buffer{}, WithMergeFields([]int{1, 2, 3}))
if err := t.Load(data); err != nil {
b.Fatal(err)
}
t.Render()
}
}
*/