MCPcopy
hub / github.com/grpc/grpc-go / BenchmarkChainUnaryInterceptor

Function BenchmarkChainUnaryInterceptor

server_test.go:179–208  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

177}
178
179func BenchmarkChainUnaryInterceptor(b *testing.B) {
180 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
181 defer cancel()
182 for _, n := range []int{1, 3, 5, 10} {
183 n := n
184 b.Run(strconv.Itoa(n), func(b *testing.B) {
185 interceptors := make([]UnaryServerInterceptor, 0, n)
186 for i := 0; i < n; i++ {
187 interceptors = append(interceptors, func(
188 ctx context.Context, req any, _ *UnaryServerInfo, handler UnaryHandler,
189 ) (any, error) {
190 return handler(ctx, req)
191 })
192 }
193
194 s := NewServer(ChainUnaryInterceptor(interceptors...))
195 b.ReportAllocs()
196 b.ResetTimer()
197 for i := 0; i < b.N; i++ {
198 if _, err := s.opts.unaryInt(ctx, nil, nil,
199 func(context.Context, any) (any, error) {
200 return nil, nil
201 },
202 ); err != nil {
203 b.Fatal(err)
204 }
205 }
206 })
207 }
208}
209
210func BenchmarkChainStreamInterceptor(b *testing.B) {
211 for _, n := range []int{1, 3, 5, 10} {

Callers

nothing calls this directly

Calls 3

ChainUnaryInterceptorFunction · 0.85
NewServerFunction · 0.70
FatalMethod · 0.65

Tested by

no test coverage detected