podman

Форк
0
/
ports_bench_test.go 
199 строк · 4.4 Кб
1
//go:build !remote
2

3
package generate
4

5
import (
6
	"fmt"
7
	"testing"
8

9
	"github.com/containers/common/libnetwork/types"
10
)
11

12
func benchmarkParsePortMapping(b *testing.B, ports []types.PortMapping) {
13
	for n := 0; n < b.N; n++ {
14
		_, _ = ParsePortMapping(ports, nil)
15
	}
16
}
17

18
func BenchmarkParsePortMappingNoPorts(b *testing.B) {
19
	benchmarkParsePortMapping(b, nil)
20
}
21

22
func BenchmarkParsePortMapping1(b *testing.B) {
23
	benchmarkParsePortMapping(b, []types.PortMapping{
24
		{
25
			HostPort:      8080,
26
			ContainerPort: 80,
27
			Protocol:      "tcp",
28
		},
29
	})
30
}
31

32
func BenchmarkParsePortMapping100(b *testing.B) {
33
	ports := make([]types.PortMapping, 0, 100)
34
	for i := uint16(8080); i < 8180; i++ {
35
		ports = append(ports, types.PortMapping{
36
			HostPort:      i,
37
			ContainerPort: i,
38
			Protocol:      "tcp",
39
		})
40
	}
41
	b.ResetTimer()
42
	benchmarkParsePortMapping(b, ports)
43
}
44

45
func BenchmarkParsePortMapping1k(b *testing.B) {
46
	ports := make([]types.PortMapping, 0, 1000)
47
	for i := uint16(8080); i < 9080; i++ {
48
		ports = append(ports, types.PortMapping{
49
			HostPort:      i,
50
			ContainerPort: i,
51
			Protocol:      "tcp",
52
		})
53
	}
54
	b.ResetTimer()
55
	benchmarkParsePortMapping(b, ports)
56
}
57

58
func BenchmarkParsePortMapping10k(b *testing.B) {
59
	ports := make([]types.PortMapping, 0, 30000)
60
	for i := uint16(8080); i < 18080; i++ {
61
		ports = append(ports, types.PortMapping{
62
			HostPort:      i,
63
			ContainerPort: i,
64
			Protocol:      "tcp",
65
		})
66
	}
67
	b.ResetTimer()
68
	benchmarkParsePortMapping(b, ports)
69
}
70

71
func BenchmarkParsePortMapping1m(b *testing.B) {
72
	ports := make([]types.PortMapping, 0, 1000000)
73
	for j := 0; j < 20; j++ {
74
		for i := uint16(1); i <= 50000; i++ {
75
			ports = append(ports, types.PortMapping{
76
				HostPort:      i,
77
				ContainerPort: i,
78
				Protocol:      "tcp",
79
				HostIP:        fmt.Sprintf("192.168.1.%d", j),
80
			})
81
		}
82
	}
83
	b.ResetTimer()
84
	benchmarkParsePortMapping(b, ports)
85
}
86

87
func BenchmarkParsePortMappingReverse100(b *testing.B) {
88
	ports := make([]types.PortMapping, 0, 100)
89
	for i := uint16(8180); i > 8080; i-- {
90
		ports = append(ports, types.PortMapping{
91
			HostPort:      i,
92
			ContainerPort: i,
93
			Protocol:      "tcp",
94
		})
95
	}
96
	b.ResetTimer()
97
	benchmarkParsePortMapping(b, ports)
98
}
99

100
func BenchmarkParsePortMappingReverse1k(b *testing.B) {
101
	ports := make([]types.PortMapping, 0, 1000)
102
	for i := uint16(9080); i > 8080; i-- {
103
		ports = append(ports, types.PortMapping{
104
			HostPort:      i,
105
			ContainerPort: i,
106
			Protocol:      "tcp",
107
		})
108
	}
109
	b.ResetTimer()
110
	benchmarkParsePortMapping(b, ports)
111
}
112

113
func BenchmarkParsePortMappingReverse10k(b *testing.B) {
114
	ports := make([]types.PortMapping, 0, 30000)
115
	for i := uint16(18080); i > 8080; i-- {
116
		ports = append(ports, types.PortMapping{
117
			HostPort:      i,
118
			ContainerPort: i,
119
			Protocol:      "tcp",
120
		})
121
	}
122
	b.ResetTimer()
123
	benchmarkParsePortMapping(b, ports)
124
}
125

126
func BenchmarkParsePortMappingReverse1m(b *testing.B) {
127
	ports := make([]types.PortMapping, 0, 1000000)
128
	for j := 0; j < 20; j++ {
129
		for i := uint16(50000); i > 0; i-- {
130
			ports = append(ports, types.PortMapping{
131
				HostPort:      i,
132
				ContainerPort: i,
133
				Protocol:      "tcp",
134
				HostIP:        fmt.Sprintf("192.168.1.%d", j),
135
			})
136
		}
137
	}
138
	b.ResetTimer()
139
	benchmarkParsePortMapping(b, ports)
140
}
141

142
func BenchmarkParsePortMappingRange1(b *testing.B) {
143
	benchmarkParsePortMapping(b, []types.PortMapping{
144
		{
145
			HostPort:      8080,
146
			ContainerPort: 80,
147
			Protocol:      "tcp",
148
			Range:         1,
149
		},
150
	})
151
}
152

153
func BenchmarkParsePortMappingRange100(b *testing.B) {
154
	benchmarkParsePortMapping(b, []types.PortMapping{
155
		{
156
			HostPort:      8080,
157
			ContainerPort: 80,
158
			Protocol:      "tcp",
159
			Range:         100,
160
		},
161
	})
162
}
163

164
func BenchmarkParsePortMappingRange1k(b *testing.B) {
165
	benchmarkParsePortMapping(b, []types.PortMapping{
166
		{
167
			HostPort:      8080,
168
			ContainerPort: 80,
169
			Protocol:      "tcp",
170
			Range:         1000,
171
		},
172
	})
173
}
174

175
func BenchmarkParsePortMappingRange10k(b *testing.B) {
176
	benchmarkParsePortMapping(b, []types.PortMapping{
177
		{
178
			HostPort:      8080,
179
			ContainerPort: 80,
180
			Protocol:      "tcp",
181
			Range:         10000,
182
		},
183
	})
184
}
185

186
func BenchmarkParsePortMappingRange1m(b *testing.B) {
187
	ports := make([]types.PortMapping, 0, 1000000)
188
	for j := 0; j < 20; j++ {
189
		ports = append(ports, types.PortMapping{
190
			HostPort:      1,
191
			ContainerPort: 1,
192
			Protocol:      "tcp",
193
			Range:         50000,
194
			HostIP:        fmt.Sprintf("192.168.1.%d", j),
195
		})
196
	}
197
	b.ResetTimer()
198
	benchmarkParsePortMapping(b, ports)
199
}
200

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.