d4bd58b98389a7b14d5ed79521cdc32ae26fd51c
[platform/upstream/grpc.git] / test / cpp / microbenchmarks / bm_fullstack_unary_ping_pong.cc
1 /*
2  *
3  * Copyright 2016 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 /* Benchmark gRPC end2end in various configurations */
20
21 #include "test/cpp/microbenchmarks/fullstack_unary_ping_pong.h"
22 #include "test/cpp/util/test_config.h"
23
24 namespace grpc {
25 namespace testing {
26
27 // force library initialization
28 auto& force_library_initialization = Library::get();
29
30 /*******************************************************************************
31  * CONFIGURATIONS
32  */
33
34 // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
35 // internal microbenchmarking tooling
36 static void SweepSizesArgs(benchmark::internal::Benchmark* b) {
37   b->Args({0, 0});
38   for (int i = 1; i <= 128 * 1024 * 1024; i *= 8) {
39     b->Args({i, 0});
40     b->Args({0, i});
41     b->Args({i, i});
42   }
43 }
44
45 BENCHMARK_TEMPLATE(BM_UnaryPingPong, TCP, NoOpMutator, NoOpMutator)
46     ->Apply(SweepSizesArgs);
47 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinTCP, NoOpMutator, NoOpMutator)
48     ->Apply(SweepSizesArgs);
49 BENCHMARK_TEMPLATE(BM_UnaryPingPong, UDS, NoOpMutator, NoOpMutator)
50     ->Args({0, 0});
51 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinUDS, NoOpMutator, NoOpMutator)
52     ->Args({0, 0});
53 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, NoOpMutator)
54     ->Apply(SweepSizesArgs);
55 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinInProcess, NoOpMutator, NoOpMutator)
56     ->Apply(SweepSizesArgs);
57 BENCHMARK_TEMPLATE(BM_UnaryPingPong, SockPair, NoOpMutator, NoOpMutator)
58     ->Args({0, 0});
59 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinSockPair, NoOpMutator, NoOpMutator)
60     ->Args({0, 0});
61 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, NoOpMutator)
62     ->Apply(SweepSizesArgs);
63 BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinInProcessCHTTP2, NoOpMutator,
64                    NoOpMutator)
65     ->Apply(SweepSizesArgs);
66 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
67                    Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
68     ->Args({0, 0});
69 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
70                    Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
71     ->Args({0, 0});
72 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
73                    Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
74                    NoOpMutator)
75     ->Args({0, 0});
76 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
77                    Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
78     ->Args({0, 0});
79 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
80                    Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
81     ->Args({0, 0});
82 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
83                    Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
84                    NoOpMutator)
85     ->Args({0, 0});
86 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
87                    Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
88     ->Args({0, 0});
89 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
90                    Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
91     ->Args({0, 0});
92 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
93                    Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
94     ->Args({0, 0});
95 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
96                    Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
97     ->Args({0, 0});
98 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
99                    Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
100     ->Args({0, 0});
101 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2,
102                    Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
103     ->Args({0, 0});
104 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
105                    Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
106     ->Args({0, 0});
107 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
108                    Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
109     ->Args({0, 0});
110 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
111                    Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
112     ->Args({0, 0});
113 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator,
114                    Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
115     ->Args({0, 0});
116 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
117                    Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
118     ->Args({0, 0});
119 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
120                    Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
121     ->Args({0, 0});
122 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
123                    Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
124                    NoOpMutator)
125     ->Args({0, 0});
126 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
127                    Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
128     ->Args({0, 0});
129 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
130                    Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
131     ->Args({0, 0});
132 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
133                    Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
134                    NoOpMutator)
135     ->Args({0, 0});
136 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
137                    Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
138     ->Args({0, 0});
139 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
140                    Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
141     ->Args({0, 0});
142 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
143                    Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
144     ->Args({0, 0});
145 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
146                    Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
147     ->Args({0, 0});
148 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
149                    Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
150     ->Args({0, 0});
151 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess,
152                    Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
153     ->Args({0, 0});
154 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
155                    Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
156     ->Args({0, 0});
157 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
158                    Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
159     ->Args({0, 0});
160 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
161                    Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
162     ->Args({0, 0});
163 BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator,
164                    Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
165     ->Args({0, 0});
166
167 }  // namespace testing
168 }  // namespace grpc
169
170 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
171 // and others do not. This allows us to support both modes.
172 namespace benchmark {
173 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
174 }  // namespace benchmark
175
176 int main(int argc, char** argv) {
177   ::benchmark::Initialize(&argc, argv);
178   ::grpc::testing::InitTest(&argc, &argv, false);
179   benchmark::RunTheBenchmarksNamespaced();
180   return 0;
181 }