From 96f8728b06740dd6b63ab463319b4795209dbec4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 13 Feb 2017 12:39:12 -0800 Subject: [PATCH] Add a comparison benchmark of acquiring a mutex --- test/cpp/microbenchmarks/bm_closure.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/cpp/microbenchmarks/bm_closure.cc b/test/cpp/microbenchmarks/bm_closure.cc index de354410e52..dac7d9c6779 100644 --- a/test/cpp/microbenchmarks/bm_closure.cc +++ b/test/cpp/microbenchmarks/bm_closure.cc @@ -170,6 +170,20 @@ static void BM_ClosureSched3OnExecCtx(benchmark::State& state) { } BENCHMARK(BM_ClosureSched3OnExecCtx); +static void BM_AcquireMutex(benchmark::State& state) { + // for comparison with the combiner stuff below + gpr_mu mu; + gpr_mu_init(&mu); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + while (state.KeepRunning()) { + gpr_mu_lock(&mu); + DoNothing(&exec_ctx, NULL, GRPC_ERROR_NONE); + gpr_mu_unlock(&mu); + } + grpc_exec_ctx_finish(&exec_ctx); +} +BENCHMARK(BM_AcquireMutex); + static void BM_ClosureSchedOnCombiner(benchmark::State& state) { grpc_combiner* combiner = grpc_combiner_create(NULL); grpc_closure c;