bm_callback_streaming_ping_pong.cc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #include "test/core/util/test_config.h"
  19. #include "test/cpp/microbenchmarks/callback_streaming_ping_pong.h"
  20. #include "test/cpp/util/test_config.h"
  21. namespace grpc {
  22. namespace testing {
  23. /*******************************************************************************
  24. * CONFIGURATIONS
  25. */
  26. // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
  27. // internal microbenchmarking tooling
  28. static void StreamingPingPongMsgSizeArgs(benchmark::internal::Benchmark* b) {
  29. // base case: 0 byte ping-pong msgs
  30. b->Args({0, 1});
  31. b->Args({0, 2});
  32. for (int msg_size = 1; msg_size <= 128 * 1024 * 1024; msg_size *= 8) {
  33. b->Args({msg_size, 1});
  34. b->Args({msg_size, 2});
  35. }
  36. }
  37. // Replace "benchmark::internal::Benchmark" with "::testing::Benchmark" to use
  38. // internal microbenchmarking tooling
  39. static void StreamingPingPongMsgsNumberArgs(benchmark::internal::Benchmark* b) {
  40. for (int msg_number = 1; msg_number <= 256 * 1024; msg_number *= 8) {
  41. b->Args({0, msg_number});
  42. b->Args({1024, msg_number});
  43. }
  44. }
  45. // Streaming with different message size
  46. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  47. NoOpMutator)
  48. ->Apply(StreamingPingPongMsgSizeArgs);
  49. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
  50. NoOpMutator)
  51. ->Apply(StreamingPingPongMsgSizeArgs);
  52. // Streaming with different message number
  53. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  54. NoOpMutator)
  55. ->Apply(StreamingPingPongMsgsNumberArgs);
  56. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, MinInProcess, NoOpMutator,
  57. NoOpMutator)
  58. ->Apply(StreamingPingPongMsgsNumberArgs);
  59. // Client context with different metadata
  60. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  61. Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
  62. ->Args({0, 1});
  63. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  64. Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
  65. ->Args({0, 1});
  66. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  67. Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
  68. NoOpMutator)
  69. ->Args({0, 1});
  70. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  71. Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
  72. ->Args({0, 1});
  73. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  74. Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
  75. ->Args({0, 1});
  76. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  77. Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
  78. NoOpMutator)
  79. ->Args({0, 1});
  80. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  81. Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
  82. ->Args({0, 1});
  83. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  84. Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
  85. ->Args({0, 1});
  86. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess,
  87. Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
  88. ->Args({0, 1});
  89. // Server context with different metadata
  90. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  91. Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
  92. ->Args({0, 1});
  93. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  94. Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
  95. ->Args({0, 1});
  96. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  97. Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
  98. ->Args({0, 1});
  99. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  100. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
  101. ->Args({0, 1});
  102. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  103. Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
  104. ->Args({0, 1});
  105. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  106. Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
  107. ->Args({0, 1});
  108. BENCHMARK_TEMPLATE(BM_CallbackBidiStreaming, InProcess, NoOpMutator,
  109. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
  110. ->Args({0, 1});
  111. } // namespace testing
  112. } // namespace grpc
  113. // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
  114. // and others do not. This allows us to support both modes.
  115. namespace benchmark {
  116. void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
  117. } // namespace benchmark
  118. int main(int argc, char** argv) {
  119. grpc::testing::TestEnvironment env(argc, argv);
  120. LibraryInitializer libInit;
  121. ::benchmark::Initialize(&argc, argv);
  122. grpc::testing::InitTest(&argc, &argv, false);
  123. benchmark::RunTheBenchmarksNamespaced();
  124. return 0;
  125. }