-
Notifications
You must be signed in to change notification settings - Fork 0
/
mux_bench_test.go
207 lines (189 loc) · 5.88 KB
/
mux_bench_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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package art
import (
"testing"
)
func BenchmarkMux_HandleMessage(b *testing.B) {
mux := NewMux("/").EnableMessagePool()
b.StopTimer()
for i, subject := range githubAPI {
_ = i
// fmt.Printf("%v api %v\n", i, subject)
mux.Handler(subject, UseSkipMessage())
}
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
for _, subject := range githubAPI {
// cpu: 13th Gen Intel(R) Core(TM) i5-1340P
// BenchmarkMux_HandleMessage
// BenchmarkMux_HandleMessage-16 10000 137605 ns/op 79285 B/op 977 allocs/op
//
// message := newMessage()
// cpu: 13th Gen Intel(R) Core(TM) i5-1340P
// BenchmarkMux_HandleMessage
// BenchmarkMux_HandleMessage-16 19755 59605 ns/op 6387 B/op 399 allocs/op
//
message := GetMessage()
message.Subject = subject
err := mux.HandleMessage(message, nil)
if err != nil {
b.Errorf("Error handling message: %v", err)
}
}
}
}
// https://github.com/julienschmidt/go-http-routing-benchmark?tab=readme-ov-file
var githubAPI = []string{
"/authorizations",
"/authorizations/{id}",
"/authorizations/clients/{client_id}",
"/applications/{client_id}/tokens/{access_token}",
"/applications/{client_id}/tokens",
"/events",
"/repos/{owner}/{repo}/events",
"/networks/{owner}/{repo}/events",
"/orgs/{org}/events",
"/users/{user}/received_events",
"/users/{user}/received_events/public",
"/users/{user}/events",
"/users/{user}/events/public",
"/users/{user}/events/orgs/{org}",
"/feeds",
"/notifications",
"/repos/{owner}/{repo}/notifications",
"/notifications/threads/{id}",
"/notifications/threads/{id}/subscription",
"/repos/{owner}/{repo}/stargazers",
"/users/{user}/starred",
"/user/starred",
"/user/starred/{owner}/{repo}",
"/repos/{owner}/{repo}/subscribers",
"/users/{user}/subscriptions",
"/user/subscriptions",
"/repos/{owner}/{repo}/subscription",
"/user/subscriptions/{owner}/{repo}",
"/users/{user}/gists",
"/gists",
"/gists/public",
"/gists/starred",
"/gists/{id}",
"/gists/{id}/star",
"/gists/{id}/forks",
"/repos/{owner}/{repo}/git/blobs/{sha}",
"/repos/{owner}/{repo}/git/blobs",
"/repos/{owner}/{repo}/git/commits/{sha}",
"/repos/{owner}/{repo}/git/commits",
"/repos/{owner}/{repo}/git/refs/*ref",
"/repos/{owner}/{repo}/git/refs",
"/repos/{owner}/{repo}/git/tags/{sha}",
"/repos/{owner}/{repo}/git/tags",
"/repos/{owner}/{repo}/git/trees/{sha}",
"/repos/{owner}/{repo}/git/trees",
"/issues",
"/user/issues",
"/orgs/{org}/issues",
"/repos/{owner}/{repo}/issues",
"/repos/{owner}/{repo}/issues/{number}",
"/repos/{owner}/{repo}/assignees",
"/repos/{owner}/{repo}/assignees/{assignee}",
"/repos/{owner}/{repo}/issues/{number}/comments",
"/repos/{owner}/{repo}/issues/comments",
"/repos/{owner}/{repo}/issues/comments/{id}",
"/repos/{owner}/{repo}/issues/{number}/events",
"/repos/{owner}/{repo}/issues/events",
"/repos/{owner}/{repo}/issues/events/{id}",
"/repos/{owner}/{repo}/labels",
"/repos/{owner}/{repo}/labels/{name}",
"/repos/{owner}/{repo}/issues/{number}/labels",
"/repos/{owner}/{repo}/issues/{number}/labels/{name}",
"/repos/{owner}/{repo}/milestones/{number}/labels",
"/repos/{owner}/{repo}/milestones",
"/repos/{owner}/{repo}/milestones/{number}",
"/emojis",
"/gitignore/templates",
"/gitignore/templates/{name}",
"/markdown",
"/markdown/raw",
"/meta",
"/rate_limit",
"/users/{user}/orgs",
"/user/orgs",
"/orgs/{org}",
"/orgs/{org}/members",
"/orgs/{org}/members/{user}",
"/orgs/{org}/public_members",
"/orgs/{org}/public_members/{user}",
"/orgs/{org}/teams",
"/teams/{id}",
"/teams/{id}/members",
"/teams/{id}/members/{user}",
"/teams/{id}/repos",
"/teams/{id}/repos/{owner}/{repo}",
"/user/teams",
"/repos/{owner}/{repo}/pulls",
"/repos/{owner}/{repo}/pulls/{number}",
"/repos/{owner}/{repo}/pulls/{number}/commits",
"/repos/{owner}/{repo}/pulls/{number}/files",
"/repos/{owner}/{repo}/pulls/{number}/merge",
"/repos/{owner}/{repo}/pulls/{number}/comments",
"/repos/{owner}/{repo}/pulls/comments",
"/repos/{owner}/{repo}/pulls/comments/{number}",
"/user/repos",
"/users/{user}/repos",
"/orgs/{org}/repos",
"/repositories",
"/repos/{owner}/{repo}",
"/repos/{owner}/{repo}/contributors",
"/repos/{owner}/{repo}/languages",
"/repos/{owner}/{repo}/teams",
"/repos/{owner}/{repo}/tags",
"/repos/{owner}/{repo}/branches",
"/repos/{owner}/{repo}/branches/{branch}",
"/repos/{owner}/{repo}/collaborators",
"/repos/{owner}/{repo}/collaborators/{user}",
"/repos/{owner}/{repo}/comments",
"/repos/{owner}/{repo}/commits/{sha}/comments",
"/repos/{owner}/{repo}/comments/{id}",
"/repos/{owner}/{repo}/commits",
"/repos/{owner}/{repo}/commits/{sha}",
"/repos/{owner}/{repo}/readme",
"/repos/{owner}/{repo}/contents/*path",
"/repos/{owner}/{repo}/{archive_format}/{ref}",
"/repos/{owner}/{repo}/keys",
"/repos/{owner}/{repo}/keys/{id}",
"/repos/{owner}/{repo}/downloads",
"/repos/{owner}/{repo}/downloads/{id}",
"/repos/{owner}/{repo}/forks",
"/repos/{owner}/{repo}/hooks",
"/repos/{owner}/{repo}/hooks/{id}",
"/repos/{owner}/{repo}/hooks/{id}/tests",
"/repos/{owner}/{repo}/merges",
"/repos/{owner}/{repo}/releases",
"/repos/{owner}/{repo}/releases/{id}",
"/repos/{owner}/{repo}/releases/{id}/assets",
"/repos/{owner}/{repo}/stats/contributors",
"/repos/{owner}/{repo}/stats/commit_activity",
"/repos/{owner}/{repo}/stats/code_frequency",
"/repos/{owner}/{repo}/stats/participation",
"/repos/{owner}/{repo}/stats/punch_card",
"/repos/{owner}/{repo}/statuses/{ref}",
"/search/repositories",
"/search/code",
"/search/issues",
"/search/users",
"/legacy/issues/search/{owner}/{repository}/{state}/{keyword}",
"/legacy/repos/search/{keyword}",
"/legacy/user/search/{keyword}",
"/legacy/user/email/{email}",
"/users/{user}",
"/user",
"/users",
"/user/emails",
"/users/{user}/followers",
"/user/followers",
"/user/following/{user}",
"/users/{user}/following/{target_user}",
"/users/{user}/keys",
"/user/keys",
"/user/keys/{id}",
}