upb: clean up benchmark.cc to make the compiler less unhappy

PiperOrigin-RevId: 550980276
pull/13675/head^2
Eric Salo 1 year ago committed by Copybara-Service
parent 512bb9ed86
commit cafbe958fd
  1. 26
      benchmarks/benchmark.cc

@ -27,6 +27,8 @@
#include <string.h> #include <string.h>
#include <vector>
#include "google/ads/googleads/v13/services/google_ads_service.upbdefs.h" #include "google/ads/googleads/v13/services/google_ads_service.upbdefs.h"
#include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor.pb.h"
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
@ -68,7 +70,7 @@ BENCHMARK(BM_ArenaOneAlloc);
static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) { static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) {
for (auto _ : state) { for (auto _ : state) {
upb_Arena* arena = upb_Arena_Init(buf, sizeof(buf), NULL); upb_Arena* arena = upb_Arena_Init(buf, sizeof(buf), nullptr);
upb_Arena_Malloc(arena, 1); upb_Arena_Malloc(arena, 1);
upb_Arena_Free(arena); upb_Arena_Free(arena);
} }
@ -151,7 +153,7 @@ bool LoadDefInit_BuildLayout(upb_DefPool* s, const _upb_DefPool_Init* init,
} }
file = google_protobuf_FileDescriptorProto_parse_ex( file = google_protobuf_FileDescriptorProto_parse_ex(
init->descriptor.data, init->descriptor.size, NULL, init->descriptor.data, init->descriptor.size, nullptr,
kUpb_DecodeOption_AliasString, arena); kUpb_DecodeOption_AliasString, arena);
*bytes += init->descriptor.size; *bytes += init->descriptor.size;
@ -262,13 +264,13 @@ static void BM_Parse_Upb_FileDesc(benchmark::State& state) {
for (auto _ : state) { for (auto _ : state) {
upb_Arena* arena; upb_Arena* arena;
if (AMode == InitBlock) { if (AMode == InitBlock) {
arena = upb_Arena_Init(buf, sizeof(buf), NULL); arena = upb_Arena_Init(buf, sizeof(buf), nullptr);
} else { } else {
arena = upb_Arena_New(); arena = upb_Arena_New();
} }
upb_benchmark_FileDescriptorProto* set = upb_benchmark_FileDescriptorProto* set =
upb_benchmark_FileDescriptorProto_parse_ex( upb_benchmark_FileDescriptorProto_parse_ex(
descriptor.data, descriptor.size, NULL, descriptor.data, descriptor.size, nullptr,
Copy == Alias ? kUpb_DecodeOption_AliasString : 0, arena); Copy == Alias ? kUpb_DecodeOption_AliasString : 0, arena);
if (!set) { if (!set) {
printf("Failed to parse.\n"); printf("Failed to parse.\n");
@ -289,26 +291,26 @@ struct Proto2Factory;
template <class P> template <class P>
struct Proto2Factory<NoArena, P> { struct Proto2Factory<NoArena, P> {
public: public:
P* GetProto() { return &proto_; } P* GetProto() { return &proto; }
private: private:
P proto_; P proto;
}; };
template <class P> template <class P>
struct Proto2Factory<UseArena, P> { struct Proto2Factory<UseArena, P> {
public: public:
P* GetProto() { return protobuf::Arena::CreateMessage<P>(&arena_); } P* GetProto() { return protobuf::Arena::CreateMessage<P>(&arena); }
private: private:
protobuf::Arena arena_; protobuf::Arena arena;
}; };
template <class P> template <class P>
struct Proto2Factory<InitBlock, P> { struct Proto2Factory<InitBlock, P> {
public: public:
Proto2Factory() : arena_(GetOptions()) {} Proto2Factory() : arena(GetOptions()) {}
P* GetProto() { return protobuf::Arena::CreateMessage<P>(&arena_); } P* GetProto() { return protobuf::Arena::CreateMessage<P>(&arena); }
private: private:
protobuf::ArenaOptions GetOptions() { protobuf::ArenaOptions GetOptions() {
@ -318,7 +320,7 @@ struct Proto2Factory<InitBlock, P> {
return opts; return opts;
} }
protobuf::Arena arena_; protobuf::Arena arena;
}; };
using FileDesc = ::upb_benchmark::FileDescriptorProto; using FileDesc = ::upb_benchmark::FileDescriptorProto;
@ -368,7 +370,7 @@ static void BM_SerializeDescriptor_Upb(benchmark::State& state) {
exit(1); exit(1);
} }
for (auto _ : state) { for (auto _ : state) {
upb_Arena* enc_arena = upb_Arena_Init(buf, sizeof(buf), NULL); upb_Arena* enc_arena = upb_Arena_Init(buf, sizeof(buf), nullptr);
size_t size; size_t size;
char* data = char* data =
upb_benchmark_FileDescriptorProto_serialize(set, enc_arena, &size); upb_benchmark_FileDescriptorProto_serialize(set, enc_arena, &size);

Loading…
Cancel
Save