aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/microbenchmarks
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2018-12-17 08:52:20 -0800
committerGravatar yang-g <yangg@google.com>2018-12-17 08:52:20 -0800
commit038a71d826f02d06397e1132f2ec1d071e90f08c (patch)
tree43afe8c684c43faae9fa0445009187ebbe643e93 /test/cpp/microbenchmarks
parentbd5d86935f6fdefd22e12eab5c64e7cb1ba7d7bc (diff)
parentb250f34b1225cde1bb19496c5cc5d66e40111052 (diff)
Merge remote-tracking branch 'upstream/master' into gpr_test_util_to_grpc_test_util
Diffstat (limited to 'test/cpp/microbenchmarks')
-rw-r--r--test/cpp/microbenchmarks/BUILD14
-rw-r--r--test/cpp/microbenchmarks/bm_byte_buffer.cc65
-rw-r--r--test/cpp/microbenchmarks/fullstack_fixtures.h2
3 files changed, 80 insertions, 1 deletions
diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD
index f8b5c54e20..b5890bece7 100644
--- a/test/cpp/microbenchmarks/BUILD
+++ b/test/cpp/microbenchmarks/BUILD
@@ -29,6 +29,7 @@ grpc_cc_test(
grpc_cc_library(
name = "helpers",
+ testonly = 1,
srcs = ["helpers.cc"],
hdrs = [
"fullstack_context_mutators.h",
@@ -55,11 +56,19 @@ grpc_cc_binary(
grpc_cc_binary(
name = "bm_arena",
+ testonly = 1,
srcs = ["bm_arena.cc"],
deps = [":helpers"],
)
grpc_cc_binary(
+ name = "bm_byte_buffer",
+ testonly = 1,
+ srcs = ["bm_byte_buffer.cc"],
+ deps = [":helpers"],
+)
+
+grpc_cc_binary(
name = "bm_channel",
testonly = 1,
srcs = ["bm_channel.cc"],
@@ -68,6 +77,7 @@ grpc_cc_binary(
grpc_cc_binary(
name = "bm_call_create",
+ testonly = 1,
srcs = ["bm_call_create.cc"],
deps = [":helpers"],
)
@@ -95,6 +105,7 @@ grpc_cc_binary(
grpc_cc_library(
name = "fullstack_streaming_ping_pong_h",
+ testonly = 1,
hdrs = [
"fullstack_streaming_ping_pong.h",
],
@@ -112,6 +123,7 @@ grpc_cc_binary(
grpc_cc_library(
name = "fullstack_streaming_pump_h",
+ testonly = 1,
hdrs = [
"fullstack_streaming_pump.h",
],
@@ -129,12 +141,14 @@ grpc_cc_binary(
grpc_cc_binary(
name = "bm_fullstack_trickle",
+ testonly = 1,
srcs = ["bm_fullstack_trickle.cc"],
deps = [":helpers"],
)
grpc_cc_library(
name = "fullstack_unary_ping_pong_h",
+ testonly = 1,
hdrs = [
"fullstack_unary_ping_pong.h",
],
diff --git a/test/cpp/microbenchmarks/bm_byte_buffer.cc b/test/cpp/microbenchmarks/bm_byte_buffer.cc
new file mode 100644
index 0000000000..a359e6f621
--- /dev/null
+++ b/test/cpp/microbenchmarks/bm_byte_buffer.cc
@@ -0,0 +1,65 @@
+/*
+ *
+ * Copyright 2015 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/* This benchmark exists to show that byte-buffer copy is size-independent */
+
+#include <memory>
+
+#include <benchmark/benchmark.h>
+#include <grpcpp/impl/grpc_library.h>
+#include <grpcpp/support/byte_buffer.h>
+#include "test/cpp/microbenchmarks/helpers.h"
+#include "test/cpp/util/test_config.h"
+
+namespace grpc {
+namespace testing {
+
+auto& force_library_initialization = Library::get();
+
+static void BM_ByteBuffer_Copy(benchmark::State& state) {
+ int num_slices = state.range(0);
+ size_t slice_size = state.range(1);
+ std::vector<grpc::Slice> slices;
+ while (num_slices > 0) {
+ num_slices--;
+ std::unique_ptr<char[]> buf(new char[slice_size]);
+ memset(buf.get(), 0, slice_size);
+ slices.emplace_back(buf.get(), slice_size);
+ }
+ grpc::ByteBuffer bb(slices.data(), num_slices);
+ while (state.KeepRunning()) {
+ grpc::ByteBuffer cc(bb);
+ }
+}
+BENCHMARK(BM_ByteBuffer_Copy)->Ranges({{1, 64}, {1, 1024 * 1024}});
+
+} // namespace testing
+} // namespace grpc
+
+// Some distros have RunSpecifiedBenchmarks under the benchmark namespace,
+// and others do not. This allows us to support both modes.
+namespace benchmark {
+void RunTheBenchmarksNamespaced() { RunSpecifiedBenchmarks(); }
+} // namespace benchmark
+
+int main(int argc, char** argv) {
+ ::benchmark::Initialize(&argc, argv);
+ ::grpc::testing::InitTest(&argc, &argv, false);
+ benchmark::RunTheBenchmarksNamespaced();
+ return 0;
+}
diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h
index 71e8d9972b..6bbf553bbd 100644
--- a/test/cpp/microbenchmarks/fullstack_fixtures.h
+++ b/test/cpp/microbenchmarks/fullstack_fixtures.h
@@ -200,7 +200,7 @@ class EndpointPairFixture : public BaseFixture {
}
grpc_server_setup_transport(server_->c_server(), server_transport_,
- nullptr, server_args, 0);
+ nullptr, server_args, nullptr);
grpc_chttp2_transport_start_reading(server_transport_, nullptr, nullptr);
}