aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/microbenchmarks/bm_metadata.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/microbenchmarks/bm_metadata.cc')
-rw-r--r--test/cpp/microbenchmarks/bm_metadata.cc45
1 files changed, 40 insertions, 5 deletions
diff --git a/test/cpp/microbenchmarks/bm_metadata.cc b/test/cpp/microbenchmarks/bm_metadata.cc
index f468690834..ee3dec2bce 100644
--- a/test/cpp/microbenchmarks/bm_metadata.cc
+++ b/test/cpp/microbenchmarks/bm_metadata.cc
@@ -42,25 +42,26 @@ extern "C" {
#include "src/core/lib/transport/transport.h"
}
+#include "test/cpp/microbenchmarks/helpers.h"
#include "third_party/benchmark/include/benchmark/benchmark.h"
-static class InitializeStuff {
- public:
- InitializeStuff() { grpc_init(); }
- ~InitializeStuff() { grpc_shutdown(); }
-} initialize_stuff;
+auto& force_library_initialization = Library::get();
static void BM_SliceFromStatic(benchmark::State& state) {
+ TrackCounters track_counters;
while (state.KeepRunning()) {
benchmark::DoNotOptimize(grpc_slice_from_static_string("abc"));
}
+ track_counters.Finish(state);
}
BENCHMARK(BM_SliceFromStatic);
static void BM_SliceFromCopied(benchmark::State& state) {
+ TrackCounters track_counters;
while (state.KeepRunning()) {
grpc_slice_unref(grpc_slice_from_copied_string("abc"));
}
+ track_counters.Finish(state);
}
BENCHMARK(BM_SliceFromCopied);
@@ -78,38 +79,47 @@ static void BM_SliceFromStreamOwnedBuffer(benchmark::State& state) {
BENCHMARK(BM_SliceFromStreamOwnedBuffer);
static void BM_SliceIntern(benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice slice = grpc_slice_from_static_string("abc");
while (state.KeepRunning()) {
grpc_slice_unref(grpc_slice_intern(slice));
}
+ track_counters.Finish(state);
}
BENCHMARK(BM_SliceIntern);
static void BM_SliceReIntern(benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice slice = grpc_slice_intern(grpc_slice_from_static_string("abc"));
while (state.KeepRunning()) {
grpc_slice_unref(grpc_slice_intern(slice));
}
grpc_slice_unref(slice);
+ track_counters.Finish(state);
}
BENCHMARK(BM_SliceReIntern);
static void BM_SliceInternStaticMetadata(benchmark::State& state) {
+ TrackCounters track_counters;
while (state.KeepRunning()) {
grpc_slice_intern(GRPC_MDSTR_GZIP);
}
+ track_counters.Finish(state);
}
BENCHMARK(BM_SliceInternStaticMetadata);
static void BM_SliceInternEqualToStaticMetadata(benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice slice = grpc_slice_from_static_string("gzip");
while (state.KeepRunning()) {
grpc_slice_intern(slice);
}
+ track_counters.Finish(state);
}
BENCHMARK(BM_SliceInternEqualToStaticMetadata);
static void BM_MetadataFromNonInternedSlices(benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = grpc_slice_from_static_string("key");
gpr_slice v = grpc_slice_from_static_string("value");
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -117,10 +127,12 @@ static void BM_MetadataFromNonInternedSlices(benchmark::State& state) {
GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_create(&exec_ctx, k, v, NULL));
}
grpc_exec_ctx_finish(&exec_ctx);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromNonInternedSlices);
static void BM_MetadataFromInternedSlices(benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key"));
gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value"));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -130,11 +142,13 @@ static void BM_MetadataFromInternedSlices(benchmark::State& state) {
grpc_exec_ctx_finish(&exec_ctx);
grpc_slice_unref(k);
grpc_slice_unref(v);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromInternedSlices);
static void BM_MetadataFromInternedSlicesAlreadyInIndex(
benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key"));
gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value"));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -146,10 +160,12 @@ static void BM_MetadataFromInternedSlicesAlreadyInIndex(
grpc_exec_ctx_finish(&exec_ctx);
grpc_slice_unref(k);
grpc_slice_unref(v);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromInternedSlicesAlreadyInIndex);
static void BM_MetadataFromInternedKey(benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key"));
gpr_slice v = grpc_slice_from_static_string("value");
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -158,11 +174,13 @@ static void BM_MetadataFromInternedKey(benchmark::State& state) {
}
grpc_exec_ctx_finish(&exec_ctx);
grpc_slice_unref(k);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromInternedKey);
static void BM_MetadataFromNonInternedSlicesWithBackingStore(
benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = grpc_slice_from_static_string("key");
gpr_slice v = grpc_slice_from_static_string("value");
char backing_store[sizeof(grpc_mdelem_data)];
@@ -174,11 +192,13 @@ static void BM_MetadataFromNonInternedSlicesWithBackingStore(
reinterpret_cast<grpc_mdelem_data*>(backing_store)));
}
grpc_exec_ctx_finish(&exec_ctx);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromNonInternedSlicesWithBackingStore);
static void BM_MetadataFromInternedSlicesWithBackingStore(
benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key"));
gpr_slice v = grpc_slice_intern(grpc_slice_from_static_string("value"));
char backing_store[sizeof(grpc_mdelem_data)];
@@ -192,11 +212,13 @@ static void BM_MetadataFromInternedSlicesWithBackingStore(
grpc_exec_ctx_finish(&exec_ctx);
grpc_slice_unref(k);
grpc_slice_unref(v);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromInternedSlicesWithBackingStore);
static void BM_MetadataFromInternedKeyWithBackingStore(
benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key"));
gpr_slice v = grpc_slice_from_static_string("value");
char backing_store[sizeof(grpc_mdelem_data)];
@@ -209,10 +231,12 @@ static void BM_MetadataFromInternedKeyWithBackingStore(
}
grpc_exec_ctx_finish(&exec_ctx);
grpc_slice_unref(k);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromInternedKeyWithBackingStore);
static void BM_MetadataFromStaticMetadataStrings(benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = GRPC_MDSTR_STATUS;
gpr_slice v = GRPC_MDSTR_200;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -221,11 +245,13 @@ static void BM_MetadataFromStaticMetadataStrings(benchmark::State& state) {
}
grpc_exec_ctx_finish(&exec_ctx);
grpc_slice_unref(k);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromStaticMetadataStrings);
static void BM_MetadataFromStaticMetadataStringsNotIndexed(
benchmark::State& state) {
+ TrackCounters track_counters;
gpr_slice k = GRPC_MDSTR_STATUS;
gpr_slice v = GRPC_MDSTR_GZIP;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -234,10 +260,12 @@ static void BM_MetadataFromStaticMetadataStringsNotIndexed(
}
grpc_exec_ctx_finish(&exec_ctx);
grpc_slice_unref(k);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataFromStaticMetadataStringsNotIndexed);
static void BM_MetadataRefUnrefExternal(benchmark::State& state) {
+ TrackCounters track_counters;
char backing_store[sizeof(grpc_mdelem_data)];
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem el =
@@ -249,10 +277,12 @@ static void BM_MetadataRefUnrefExternal(benchmark::State& state) {
}
GRPC_MDELEM_UNREF(&exec_ctx, el);
grpc_exec_ctx_finish(&exec_ctx);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataRefUnrefExternal);
static void BM_MetadataRefUnrefInterned(benchmark::State& state) {
+ TrackCounters track_counters;
char backing_store[sizeof(grpc_mdelem_data)];
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_slice k = grpc_slice_intern(grpc_slice_from_static_string("key"));
@@ -266,10 +296,12 @@ static void BM_MetadataRefUnrefInterned(benchmark::State& state) {
}
GRPC_MDELEM_UNREF(&exec_ctx, el);
grpc_exec_ctx_finish(&exec_ctx);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataRefUnrefInterned);
static void BM_MetadataRefUnrefAllocated(benchmark::State& state) {
+ TrackCounters track_counters;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem el =
grpc_mdelem_create(&exec_ctx, grpc_slice_from_static_string("a"),
@@ -279,10 +311,12 @@ static void BM_MetadataRefUnrefAllocated(benchmark::State& state) {
}
GRPC_MDELEM_UNREF(&exec_ctx, el);
grpc_exec_ctx_finish(&exec_ctx);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataRefUnrefAllocated);
static void BM_MetadataRefUnrefStatic(benchmark::State& state) {
+ TrackCounters track_counters;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_mdelem el =
grpc_mdelem_create(&exec_ctx, GRPC_MDSTR_STATUS, GRPC_MDSTR_200, NULL);
@@ -291,6 +325,7 @@ static void BM_MetadataRefUnrefStatic(benchmark::State& state) {
}
GRPC_MDELEM_UNREF(&exec_ctx, el);
grpc_exec_ctx_finish(&exec_ctx);
+ track_counters.Finish(state);
}
BENCHMARK(BM_MetadataRefUnrefStatic);