From 4890735ce2f35f0683469a8cd3b6952e7232b2a1 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 14 Oct 2020 12:50:58 -0700 Subject: [PATCH] Added benchmark for descriptor loading. --- tests/benchmark.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/benchmark.cc b/tests/benchmark.cc index 15544afe1b..5adce49a66 100644 --- a/tests/benchmark.cc +++ b/tests/benchmark.cc @@ -4,6 +4,7 @@ #include "google/protobuf/descriptor.upb.h" #include "google/protobuf/descriptor.upbdefs.h" #include "google/protobuf/descriptor.pb.h" +#include "upb/def.hpp" upb_strview descriptor = google_protobuf_descriptor_proto_upbdefinit.descriptor; namespace protobuf = ::google::protobuf; @@ -29,6 +30,22 @@ static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) { } BENCHMARK(BM_ArenaInitialBlockOneAlloc); +static void BM_LoadDescriptor(benchmark::State& state) { + for (auto _ : state) { + upb::SymbolTable symtab; + upb::Arena arena; + google_protobuf_FileDescriptorProto* file_proto = + google_protobuf_FileDescriptorProto_parse(descriptor.data, + descriptor.size, arena.ptr()); + upb::FileDefPtr file_def = symtab.AddFile(file_proto, NULL); + if (!file_def) { + printf("Failed to add file.\n"); + exit(1); + } + } +} +BENCHMARK(BM_LoadDescriptor); + static void BM_ParseDescriptor_Upb_LargeInitialBlock(benchmark::State& state) { size_t bytes = 0; for (auto _ : state) {