Merge pull request #318 from haberman/descriptor-load-benchmark

Benchmarks for descriptor loading time.
pull/13171/head
Joshua Haberman 4 years ago committed by GitHub
commit d5c64476fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      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,41 @@ static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) {
}
BENCHMARK(BM_ArenaInitialBlockOneAlloc);
static void BM_LoadDescriptor_Upb(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);
}
}
state.SetBytesProcessed(state.iterations() * descriptor.size);
}
BENCHMARK(BM_LoadDescriptor_Upb);
static void BM_LoadDescriptor_Proto2(benchmark::State& state) {
for (auto _ : state) {
protobuf::Arena arena;
protobuf::StringPiece input(descriptor.data,descriptor.size);
auto proto = protobuf::Arena::CreateMessage<protobuf::FileDescriptorProto>(
&arena);
protobuf::DescriptorPool pool;
bool ok = proto->ParseFrom<protobuf::MessageLite::kMergePartial>(input) &&
pool.BuildFile(*proto) != nullptr;
if (!ok) {
printf("Failed to add file.\n");
exit(1);
}
}
state.SetBytesProcessed(state.iterations() * descriptor.size);
}
BENCHMARK(BM_LoadDescriptor_Proto2);
static void BM_ParseDescriptor_Upb_LargeInitialBlock(benchmark::State& state) {
size_t bytes = 0;
for (auto _ : state) {

Loading…
Cancel
Save