bm_callback_unary_ping_pong.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_unary_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 SweepSizesArgs(benchmark::internal::Benchmark* b) {
  29. b->Args({0, 0});
  30. for (int i = 1; i <= 128 * 1024 * 1024; i *= 8) {
  31. // First argument is the message size of request
  32. // Second argument is the message size of response
  33. b->Args({i, 0});
  34. b->Args({0, i});
  35. b->Args({i, i});
  36. }
  37. }
  38. // Unary ping pong with different message size of request and response
  39. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  40. NoOpMutator)
  41. ->Apply(SweepSizesArgs);
  42. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcess, NoOpMutator,
  43. NoOpMutator)
  44. ->Apply(SweepSizesArgs);
  45. // Client context with different metadata
  46. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  47. Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator)
  48. ->Args({0, 0});
  49. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  50. Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator)
  51. ->Args({0, 0});
  52. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  53. Client_AddMetadata<RandomBinaryMetadata<100>, 1>,
  54. NoOpMutator)
  55. ->Args({0, 0});
  56. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  57. Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator)
  58. ->Args({0, 0});
  59. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  60. Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator)
  61. ->Args({0, 0});
  62. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  63. Client_AddMetadata<RandomBinaryMetadata<100>, 2>,
  64. NoOpMutator)
  65. ->Args({0, 0});
  66. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  67. Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator)
  68. ->Args({0, 0});
  69. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  70. Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator)
  71. ->Args({0, 0});
  72. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess,
  73. Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator)
  74. ->Args({0, 0});
  75. // Server context with different metadata
  76. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  77. Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>)
  78. ->Args({0, 0});
  79. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  80. Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>)
  81. ->Args({0, 0});
  82. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  83. Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>)
  84. ->Args({0, 0});
  85. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  86. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>)
  87. ->Args({0, 0});
  88. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  89. Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>)
  90. ->Args({0, 0});
  91. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  92. Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>)
  93. ->Args({0, 0});
  94. BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
  95. Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>)
  96. ->Args({0, 0});
  97. } // namespace testing
  98. } // namespace grpc
  99. // Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
  100. // and others do not. This allows us to support both modes.
  101. namespace benchmark {
  102. void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
  103. } // namespace benchmark
  104. int main(int argc, char** argv) {
  105. grpc::testing::TestEnvironment env(argc, argv);
  106. LibraryInitializer libInit;
  107. ::benchmark::Initialize(&argc, argv);
  108. grpc::testing::InitTest(&argc, &argv, false);
  109. benchmark::RunTheBenchmarksNamespaced();
  110. return 0;
  111. }