MCPcopy
hub / github.com/prometheus/client_golang / BenchmarkClient

Function BenchmarkClient

api/client_test.go:179–211  ·  api/client_test.go::BenchmarkClient
(b *testing.B)

Source from the content-addressed store, hash-verified

177}
178
179func BenchmarkClient(b *testing.B) {
180 b.ReportAllocs()
181 ctx := context.Background()
182
183 for _, sizeKB := range []int{4, 50, 1000, 2000} {
184 b.Run(fmt.Sprintf("%dKB", sizeKB), func(b *testing.B) {
185 testServer := httptest.NewServer(serveSpaces{sizeKB})
186 defer testServer.Close()
187
188 client, err := NewClient(Config{
189 Address: testServer.URL,
190 })
191 if err != nil {
192 b.Fatalf("Failed to initialize client: %v", err)
193 }
194 url, err := url.Parse(testServer.URL + "/prometheus/api/v1/query?query=up")
195 if err != nil {
196 b.Fatalf("Failed to parse url: %v", err)
197 }
198 req := &http.Request{
199 URL: url,
200 }
201 b.ResetTimer()
202 for i := 0; i < b.N; i++ {
203 _, _, err := client.Do(ctx, req)
204 if err != nil {
205 b.Fatalf("Query failed: %v", err)
206 }
207 }
208 b.StopTimer()
209 })
210 }
211}

Callers

nothing calls this directly

Calls 3

DoMethod · 0.95
NewClientFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected