xref: /aosp_15_r20/external/grpc-grpc/test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 //
2 //
3 // Copyright 2019 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include "test/core/util/test_config.h"
20 #include "test/cpp/microbenchmarks/callback_unary_ping_pong.h"
21 #include "test/cpp/util/test_config.h"
22 
23 namespace grpc {
24 namespace testing {
25 
26 //******************************************************************************
27 // CONFIGURATIONS
28 //
29 
30 // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
31 // internal microbenchmarking tooling
SweepSizesArgs(benchmark::internal::Benchmark * b)32 static void SweepSizesArgs(benchmark::internal::Benchmark* b) {
33   b->Args({0, 0});
34   for (int i = 1; i <= 128 * 1024 * 1024; i *= 8) {
35     // First argument is the message size of request
36     // Second argument is the message size of response
37     b->Args({i, 0});
38     b->Args({0, i});
39     b->Args({i, i});
40   }
41 }
42 
43 // Unary ping pong with different message size of request and response
44 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
45                    NoOpMutator)
46     ->Apply(SweepSizesArgs);
47 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcess, NoOpMutator,
48                    NoOpMutator)
49     ->Apply(SweepSizesArgs);
50 
51 // Client context with different metadata
52 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
53                    Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
54     ->Args({0, 0});
55 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
56                    Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
57     ->Args({0, 0});
58 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
59                    Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
60                    NoOpMutator)
61     ->Args({0, 0});
62 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
63                    Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
64     ->Args({0, 0});
65 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
66                    Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
67     ->Args({0, 0});
68 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
69                    Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
70                    NoOpMutator)
71     ->Args({0, 0});
72 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
73                    Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
74     ->Args({0, 0});
75 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
76                    Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
77     ->Args({0, 0});
78 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
79                    Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
80     ->Args({0, 0});
81 
82 // Server context with different metadata
83 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
84                    Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
85     ->Args({0, 0});
86 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
87                    Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
88     ->Args({0, 0});
89 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
90                    Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
91     ->Args({0, 0});
92 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
93                    Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
94     ->Args({0, 0});
95 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
96                    Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
97     ->Args({0, 0});
98 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
99                    Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
100     ->Args({0, 0});
101 BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
102                    Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
103     ->Args({0, 0});
104 }  // namespace testing
105 }  // namespace grpc
106 
107 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
108 // and others do not. This allows us to support both modes.
109 namespace benchmark {
RunTheBenchmarksNamespaced()110 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
111 }  // namespace benchmark
112 
main(int argc,char ** argv)113 int main(int argc, char** argv) {
114   grpc::testing::TestEnvironment env(&argc, argv);
115   LibraryInitializer libInit;
116   ::benchmark::Initialize(&argc, argv);
117   grpc::testing::InitTest(&argc, &argv, false);
118   benchmark::RunTheBenchmarksNamespaced();
119   return 0;
120 }
121