From 30f01afa83fde84bcd1629315f702d015900d816 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 10 Oct 2020 20:47:01 -0700 Subject: [PATCH] Added LargeInitialBlock test for proto2. --- tests/benchmark.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/benchmark.cc b/tests/benchmark.cc index f8e8441f16..eb7fdbba0d 100644 --- a/tests/benchmark.cc +++ b/tests/benchmark.cc @@ -81,7 +81,7 @@ static void BM_ParseDescriptor_Proto2_NoArena(benchmark::State& state) { } BENCHMARK(BM_ParseDescriptor_Proto2_NoArena); -static void BM_ParseDescriptor_Proto2_WithArena(benchmark::State& state) { +static void BM_ParseDescriptor_Proto2_Arena(benchmark::State& state) { size_t bytes = 0; for (auto _ : state) { protobuf::Arena arena; @@ -97,7 +97,28 @@ static void BM_ParseDescriptor_Proto2_WithArena(benchmark::State& state) { } state.SetBytesProcessed(state.iterations() * descriptor.size); } -BENCHMARK(BM_ParseDescriptor_Proto2_WithArena); +BENCHMARK(BM_ParseDescriptor_Proto2_Arena); + +static void BM_ParseDescriptor_Proto2_Arena_LargeInitialBlock(benchmark::State& state) { + size_t bytes = 0; + protobuf::ArenaOptions opts; + opts.initial_block = buf; + opts.initial_block_size = sizeof(buf); + for (auto _ : state) { + protobuf::Arena arena(opts); + auto proto = protobuf::Arena::CreateMessage( + &arena); + bool ok = proto->ParsePartialFromArray(descriptor.data, descriptor.size); + + if (!ok) { + printf("Failed to parse.\n"); + exit(1); + } + bytes += descriptor.size; + } + state.SetBytesProcessed(state.iterations() * descriptor.size); +} +BENCHMARK(BM_ParseDescriptor_Proto2_Arena_LargeInitialBlock); static void BM_SerializeDescriptor_Proto2(benchmark::State& state) { size_t bytes = 0;