MCPcopy
hub / github.com/connectrpc/connect-go / BenchmarkConnect

Function BenchmarkConnect

bench_test.go:34–200  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

32)
33
34func BenchmarkConnect(b *testing.B) {
35 mux := http.NewServeMux()
36 mux.Handle(
37 pingv1connect.NewPingServiceHandler(
38 &ExamplePingServer{},
39 ),
40 )
41 server := httptest.NewUnstartedServer(mux)
42 p := new(http.Protocols)
43 p.SetHTTP1(true)
44 p.SetUnencryptedHTTP2(true)
45 server.Config.Protocols = p
46 server.Start()
47 b.Cleanup(server.Close)
48
49 httpClient := server.Client()
50 httpTransport, ok := httpClient.Transport.(*http.Transport)
51 assert.True(b, ok)
52 httpTransport.DisableCompression = true
53 clientProtos := new(http.Protocols)
54 clientProtos.SetUnencryptedHTTP2(true)
55 httpTransport.Protocols = clientProtos
56
57 clients := []struct {
58 name string
59 opts []connect.ClientOption
60 }{{
61 name: "connect",
62 opts: []connect.ClientOption{},
63 }, {
64 name: "grpc",
65 opts: []connect.ClientOption{
66 connect.WithGRPC(),
67 },
68 }, {
69 name: "grpcweb",
70 opts: []connect.ClientOption{
71 connect.WithGRPCWeb(),
72 },
73 }}
74
75 twoMiB := strings.Repeat("a", 2*1024*1024)
76 for _, client := range clients {
77 b.Run(client.name, func(b *testing.B) {
78 client := pingv1connect.NewPingServiceClient(
79 httpClient,
80 server.URL,
81 connect.WithSendGzip(),
82 connect.WithClientOptions(client.opts...),
83 )
84
85 ctx := b.Context()
86 b.Run("unary_big", func(b *testing.B) {
87 b.ReportAllocs()
88 b.RunParallel(func(pb *testing.PB) {
89 for pb.Next() {
90 if _, err := client.Ping(
91 ctx, &pingv1.PingRequest{Text: twoMiB},

Callers

nothing calls this directly

Calls 15

PingMethod · 0.95
SumMethod · 0.95
CountUpMethod · 0.95
CumSumMethod · 0.95
NewPingServiceHandlerFunction · 0.92
TrueFunction · 0.92
WithGRPCFunction · 0.92
WithGRPCWebFunction · 0.92
NewPingServiceClientFunction · 0.92
WithSendGzipFunction · 0.92
WithClientOptionsFunction · 0.92
CleanupMethod · 0.80

Tested by

no test coverage detected