|
|
|
@ -9,9 +9,10 @@ |
|
|
|
|
#include "benchmarks/descriptor_sv.pb.h" |
|
|
|
|
|
|
|
|
|
// For for benchmarks of building descriptors.
|
|
|
|
|
#include "google/protobuf/descriptor.upb.h" |
|
|
|
|
#include "google/ads/googleads/v5/services/google_ads_service.upbdefs.h" |
|
|
|
|
#include "google/protobuf/descriptor.pb.h" |
|
|
|
|
|
|
|
|
|
#include "google/protobuf/descriptor.upb.h" |
|
|
|
|
#include "google/protobuf/descriptor.upbdefs.h" |
|
|
|
|
#include "upb/def.hpp" |
|
|
|
|
|
|
|
|
|
upb_strview descriptor = benchmarks_descriptor_proto_upbdefinit.descriptor; |
|
|
|
@ -20,6 +21,16 @@ namespace protobuf = ::google::protobuf; |
|
|
|
|
/* A buffer big enough to parse descriptor.proto without going to heap. */ |
|
|
|
|
char buf[65535]; |
|
|
|
|
|
|
|
|
|
void CollectFileDescriptors(const upb_def_init* file, |
|
|
|
|
std::vector<upb_strview>& serialized_files, |
|
|
|
|
std::unordered_set<const upb_def_init*>& seen) { |
|
|
|
|
if (!seen.insert(file).second) return; |
|
|
|
|
for (upb_def_init **deps = file->deps; *deps; deps++) { |
|
|
|
|
CollectFileDescriptors(*deps, serialized_files, seen); |
|
|
|
|
} |
|
|
|
|
serialized_files.push_back(file->descriptor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void BM_ArenaOneAlloc(benchmark::State& state) { |
|
|
|
|
for (auto _ : state) { |
|
|
|
|
upb_arena* arena = upb_arena_new(); |
|
|
|
@ -39,22 +50,28 @@ static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) { |
|
|
|
|
BENCHMARK(BM_ArenaInitialBlockOneAlloc); |
|
|
|
|
|
|
|
|
|
static void BM_LoadDescriptor_Upb(benchmark::State& state) { |
|
|
|
|
size_t bytes_per_iter; |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
google_protobuf_DescriptorProto_getmsgdef(symtab.ptr()); |
|
|
|
|
bytes_per_iter = _upb_symtab_bytesloaded(symtab.ptr()); |
|
|
|
|
} |
|
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
|
} |
|
|
|
|
BENCHMARK(BM_LoadDescriptor_Upb); |
|
|
|
|
|
|
|
|
|
static void BM_LoadAdsDescriptor_Upb(benchmark::State& state) { |
|
|
|
|
size_t bytes_per_iter; |
|
|
|
|
for (auto _ : state) { |
|
|
|
|
upb::SymbolTable symtab; |
|
|
|
|
google_ads_googleads_v5_services_SearchGoogleAdsRequest_getmsgdef( |
|
|
|
|
symtab.ptr()); |
|
|
|
|
bytes_per_iter = _upb_symtab_bytesloaded(symtab.ptr()); |
|
|
|
|
} |
|
|
|
|
state.SetBytesProcessed(state.iterations() * bytes_per_iter); |
|
|
|
|
} |
|
|
|
|
BENCHMARK(BM_LoadAdsDescriptor_Upb); |
|
|
|
|
|
|
|
|
|
static void BM_LoadDescriptor_Proto2(benchmark::State& state) { |
|
|
|
|
for (auto _ : state) { |
|
|
|
|
protobuf::Arena arena; |
|
|
|
@ -73,6 +90,35 @@ static void BM_LoadDescriptor_Proto2(benchmark::State& state) { |
|
|
|
|
} |
|
|
|
|
BENCHMARK(BM_LoadDescriptor_Proto2); |
|
|
|
|
|
|
|
|
|
static void BM_LoadAdsDescriptor_Proto2(benchmark::State& state) { |
|
|
|
|
extern upb_def_init google_ads_googleads_v5_services_google_ads_service_proto_upbdefinit; |
|
|
|
|
std::vector<upb_strview> serialized_files; |
|
|
|
|
std::unordered_set<const upb_def_init*> seen_files; |
|
|
|
|
CollectFileDescriptors( |
|
|
|
|
&google_ads_googleads_v5_services_google_ads_service_proto_upbdefinit, |
|
|
|
|
serialized_files, seen_files); |
|
|
|
|
size_t bytes_per_iter; |
|
|
|
|
for (auto _ : state) { |
|
|
|
|
bytes_per_iter = 0; |
|
|
|
|
protobuf::Arena arena; |
|
|
|
|
protobuf::DescriptorPool pool; |
|
|
|
|
for (auto file : serialized_files) { |
|
|
|
|
protobuf::StringPiece input(file.data, file.size); |
|
|
|
|
auto proto = protobuf::Arena::CreateMessage<protobuf::FileDescriptorProto>( |
|
|
|
|
&arena); |
|
|
|
|
bool ok = proto->ParseFrom<protobuf::MessageLite::kMergePartial>(input) && |
|
|
|
|
pool.BuildFile(*proto) != nullptr; |
|
|
|
|
if (!ok) { |
|
|
|
|
printf("Failed to add file.\n"); |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
bytes_per_iter += input.size(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
state.SetBytesProcessed(state.iterations() * bytes_per_iter); |
|
|
|
|
} |
|
|
|
|
BENCHMARK(BM_LoadAdsDescriptor_Proto2); |
|
|
|
|
|
|
|
|
|
static void BM_Parse_Upb_FileDesc_WithArena(benchmark::State& state) { |
|
|
|
|
size_t bytes = 0; |
|
|
|
|
for (auto _ : state) { |
|
|
|
|