aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/microbenchmarks
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-03-09 21:57:42 -0800
committerGravatar Craig Tiller <ctiller@google.com>2017-03-09 21:57:42 -0800
commiteb41e6438fa1224b3eeeb5726c1e64fdec1fa96b (patch)
treee18209cc63c2d4ac6b6392376d932a635b1af020 /test/cpp/microbenchmarks
parent2b182c2b4b82f3443111f79227de6a492fa22c78 (diff)
parent89addaedc09d3c61be0eee63dff9e554cfc2db09 (diff)
Merge github.com:grpc/grpc into poll-wakeup
Diffstat (limited to 'test/cpp/microbenchmarks')
-rw-r--r--test/cpp/microbenchmarks/bm_call_create.cc30
-rw-r--r--test/cpp/microbenchmarks/bm_error.cc30
2 files changed, 60 insertions, 0 deletions
diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc
index f25bcd2df8..92a0d18fbc 100644
--- a/test/cpp/microbenchmarks/bm_call_create.cc
+++ b/test/cpp/microbenchmarks/bm_call_create.cc
@@ -37,6 +37,7 @@
#include <string.h>
#include <sstream>
+#include <grpc++/channel.h>
#include <grpc++/support/channel_arguments.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
@@ -55,6 +56,8 @@ extern "C" {
#include "src/core/lib/transport/transport_impl.h"
}
+#include "src/cpp/client/create_channel_internal.h"
+#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/helpers.h"
#include "third_party/benchmark/include/benchmark/benchmark.h"
@@ -105,6 +108,33 @@ static void BM_CallCreateDestroy(benchmark::State &state) {
BENCHMARK_TEMPLATE(BM_CallCreateDestroy, InsecureChannel);
BENCHMARK_TEMPLATE(BM_CallCreateDestroy, LameChannel);
+static void *tag(int i) {
+ return reinterpret_cast<void *>(static_cast<intptr_t>(i));
+}
+
+static void BM_LameChannelCallCreateCpp(benchmark::State &state) {
+ TrackCounters track_counters;
+ auto stub =
+ grpc::testing::EchoTestService::NewStub(grpc::CreateChannelInternal(
+ "", grpc_lame_client_channel_create(
+ "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah")));
+ grpc::CompletionQueue cq;
+ grpc::testing::EchoRequest send_request;
+ grpc::testing::EchoResponse recv_response;
+ grpc::Status recv_status;
+ while (state.KeepRunning()) {
+ grpc::ClientContext cli_ctx;
+ auto reader = stub->AsyncEcho(&cli_ctx, send_request, &cq);
+ reader->Finish(&recv_response, &recv_status, tag(0));
+ void *t;
+ bool ok;
+ GPR_ASSERT(cq.Next(&t, &ok));
+ GPR_ASSERT(ok);
+ }
+ track_counters.Finish(state);
+}
+BENCHMARK(BM_LameChannelCallCreateCpp);
+
static void FilterDestroy(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
gpr_free(arg);
diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc
index 95f19e7586..ff1519b1f4 100644
--- a/test/cpp/microbenchmarks/bm_error.cc
+++ b/test/cpp/microbenchmarks/bm_error.cc
@@ -71,6 +71,36 @@ static void BM_ErrorCreateAndSetStatus(benchmark::State& state) {
}
BENCHMARK(BM_ErrorCreateAndSetStatus);
+static void BM_ErrorCreateAndSetIntAndStr(benchmark::State& state) {
+ while (state.KeepRunning()) {
+ GRPC_ERROR_UNREF(grpc_error_set_str(
+ grpc_error_set_int(GRPC_ERROR_CREATE("GOAWAY received"),
+ GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)0),
+ GRPC_ERROR_STR_RAW_BYTES, "raw bytes"));
+ }
+}
+BENCHMARK(BM_ErrorCreateAndSetIntAndStr);
+
+static void BM_ErrorCreateAndSetIntLoop(benchmark::State& state) {
+ grpc_error* error = GRPC_ERROR_CREATE("Error");
+ int n = 0;
+ while (state.KeepRunning()) {
+ error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, n++);
+ }
+ GRPC_ERROR_UNREF(error);
+}
+BENCHMARK(BM_ErrorCreateAndSetIntLoop);
+
+static void BM_ErrorCreateAndSetStrLoop(benchmark::State& state) {
+ grpc_error* error = GRPC_ERROR_CREATE("Error");
+ const char* str = "hello";
+ while (state.KeepRunning()) {
+ error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, str);
+ }
+ GRPC_ERROR_UNREF(error);
+}
+BENCHMARK(BM_ErrorCreateAndSetStrLoop);
+
static void BM_ErrorRefUnref(benchmark::State& state) {
TrackCounters track_counters;
grpc_error* error = GRPC_ERROR_CREATE("Error");