3 * Copyright 2019 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "test/cpp/microbenchmarks/callback_streaming_ping_pong.h"
20 #include "test/cpp/util/test_config.h"
25 /*******************************************************************************
29 // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
30 // internal microbenchmarking tooling
31 static void StreamingPingPongMsgSizeArgs(benchmark::internal::Benchmark* b) {
32 // base case: 0 byte ping-pong msgs
36 for (int msg_size = 1; msg_size <= 128 * 1024 * 1024; msg_size *= 8) {
37 b->Args({msg_size, 1});
38 b->Args({msg_size, 2});
42 // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
43 // internal microbenchmarking tooling
44 static void StreamingPingPongMsgsNumberArgs(benchmark::internal::Benchmark* b) {
45 for (int msg_number = 1; msg_number <= 256 * 1024; msg_number *= 8) {
46 b->Args({0, msg_number});
47 b->Args({1024, msg_number});
51 // Streaming with different message size
52 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
54 ->Apply(StreamingPingPongMsgSizeArgs);
55 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
57 ->Apply(StreamingPingPongMsgSizeArgs);
59 // Streaming with different message number
60 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
62 ->Apply(StreamingPingPongMsgsNumberArgs);
63 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
65 ->Apply(StreamingPingPongMsgsNumberArgs);
67 // Client context with different metadata
68 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
69 Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
71 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
72 Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
74 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
75 Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
78 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
79 Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
81 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
82 Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
84 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
85 Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
88 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
89 Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
91 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
92 Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
94 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
95 Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
98 // Server context with different metadata
99 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
100 Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
102 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
103 Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
105 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
106 Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
108 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
109 Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
111 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
112 Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
114 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
115 Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
117 BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
118 Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
121 } // namespace testing
124 // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
125 // and others do not. This allows us to support both modes.
126 namespace benchmark {
127 void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
128 } // namespace benchmark
130 int main(int argc, char** argv) {
131 LibraryInitializer libInit;
132 ::benchmark::Initialize(&argc, argv);
133 ::grpc::testing::InitTest(&argc, &argv, false);
134 benchmark::RunTheBenchmarksNamespaced();