From 025cc2ec3dd5d979cdf5bcce77d49656ffa184b6 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 26 Apr 2020 13:26:57 -0700 Subject: [PATCH] New arena benchmarks that actually hit the heap. (#275) --- tests/benchmark.cc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/benchmark.cc b/tests/benchmark.cc index bcb4ec78b6..747e51e0ac 100644 --- a/tests/benchmark.cc +++ b/tests/benchmark.cc @@ -9,15 +9,23 @@ upb_strview descriptor = google_protobuf_descriptor_proto_upbdefinit.descriptor; /* A buffer big enough to parse descriptor.proto without going to heap. */ char buf[65535]; -static void BM_CreateArena(benchmark::State& state) { +static void BM_CreateArenaNoHeap(benchmark::State& state) { for (auto _ : state) { upb_arena* arena = upb_arena_init(buf, sizeof(buf), NULL); upb_arena_free(arena); } } +BENCHMARK(BM_CreateArenaNoHeap); + +static void BM_CreateArena(benchmark::State& state) { + for (auto _ : state) { + upb_arena* arena = upb_arena_new(); + upb_arena_free(arena); + } +} BENCHMARK(BM_CreateArena); -static void BM_ParseDescriptor(benchmark::State& state) { +static void BM_ParseDescriptorNoHeap(benchmark::State& state) { size_t bytes = 0; for (auto _ : state) { upb_arena* arena = upb_arena_init(buf, sizeof(buf), NULL); @@ -33,4 +41,22 @@ static void BM_ParseDescriptor(benchmark::State& state) { } state.SetBytesProcessed(state.iterations() * descriptor.size); } +BENCHMARK(BM_ParseDescriptorNoHeap); + +static void BM_ParseDescriptor(benchmark::State& state) { + size_t bytes = 0; + for (auto _ : state) { + upb_arena* arena = upb_arena_new(); + google_protobuf_FileDescriptorProto* set = + google_protobuf_FileDescriptorProto_parse(descriptor.data, + descriptor.size, arena); + if (!set) { + printf("Failed to parse.\n"); + exit(1); + } + bytes += descriptor.size; + upb_arena_free(arena); + } + state.SetBytesProcessed(state.iterations() * descriptor.size); +} BENCHMARK(BM_ParseDescriptor);