MCPcopy Create free account
hub / github.com/compozy/agh / BenchmarkDoRequestPostJSON

Function BenchmarkDoRequestPostJSON

internal/cli/perf_bench_test.go:50–79  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

48}
49
50func BenchmarkDoRequestPostJSON(b *testing.B) {
51 ctx := context.Background()
52 client := &unixSocketClient{
53 socketPath: "/tmp/agh.sock",
54 httpClient: &http.Client{
55 Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
56 if req.Body != nil {
57 if _, err := io.Copy(io.Discard, req.Body); err != nil {
58 return nil, err
59 }
60 if err := req.Body.Close(); err != nil {
61 return nil, err
62 }
63 }
64 return newHTTPResponse(http.StatusNoContent, ""), nil
65 }),
66 },
67 }
68
69 b.ReportAllocs()
70 for b.Loop() {
71 response, err := client.doRequest(ctx, http.MethodPost, "/api/sessions", nil, benchmarkRequestBody)
72 if err != nil {
73 b.Fatalf("doRequest() error = %v", err)
74 }
75 if err := response.Body.Close(); err != nil {
76 b.Fatalf("response.Body.Close() error = %v", err)
77 }
78 }
79}
80
81func buildBenchmarkTableRows(count int) [][]string {
82 rows := make([][]string, 0, count)

Callers

nothing calls this directly

Calls 4

doRequestMethod · 0.95
roundTripperFuncFuncType · 0.85
newHTTPResponseFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected