|
|
@ -3,8 +3,10 @@ |
|
|
|
#include <benchmark/benchmark.h> |
|
|
|
#include <benchmark/benchmark.h> |
|
|
|
#include "google/protobuf/descriptor.upb.h" |
|
|
|
#include "google/protobuf/descriptor.upb.h" |
|
|
|
#include "google/protobuf/descriptor.upbdefs.h" |
|
|
|
#include "google/protobuf/descriptor.upbdefs.h" |
|
|
|
|
|
|
|
#include "google/protobuf/descriptor.pb.h" |
|
|
|
|
|
|
|
|
|
|
|
upb_strview descriptor = google_protobuf_descriptor_proto_upbdefinit.descriptor; |
|
|
|
upb_strview descriptor = google_protobuf_descriptor_proto_upbdefinit.descriptor; |
|
|
|
|
|
|
|
namespace protobuf = ::google::protobuf; |
|
|
|
|
|
|
|
|
|
|
|
/* A buffer big enough to parse descriptor.proto without going to heap. */ |
|
|
|
/* A buffer big enough to parse descriptor.proto without going to heap. */ |
|
|
|
char buf[65535]; |
|
|
|
char buf[65535]; |
|
|
@ -27,7 +29,7 @@ static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) { |
|
|
|
} |
|
|
|
} |
|
|
|
BENCHMARK(BM_ArenaInitialBlockOneAlloc); |
|
|
|
BENCHMARK(BM_ArenaInitialBlockOneAlloc); |
|
|
|
|
|
|
|
|
|
|
|
static void BM_ParseDescriptorNoHeap(benchmark::State& state) { |
|
|
|
static void BM_ParseDescriptor_Upb_LargeInitialBlock(benchmark::State& state) { |
|
|
|
size_t bytes = 0; |
|
|
|
size_t bytes = 0; |
|
|
|
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), NULL); |
|
|
@ -43,9 +45,9 @@ static void BM_ParseDescriptorNoHeap(benchmark::State& state) { |
|
|
|
} |
|
|
|
} |
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
} |
|
|
|
} |
|
|
|
BENCHMARK(BM_ParseDescriptorNoHeap); |
|
|
|
BENCHMARK(BM_ParseDescriptor_Upb_LargeInitialBlock); |
|
|
|
|
|
|
|
|
|
|
|
static void BM_ParseDescriptor(benchmark::State& state) { |
|
|
|
static void BM_ParseDescriptor_Upb(benchmark::State& state) { |
|
|
|
size_t bytes = 0; |
|
|
|
size_t bytes = 0; |
|
|
|
for (auto _ : state) { |
|
|
|
for (auto _ : state) { |
|
|
|
upb_arena* arena = upb_arena_new(); |
|
|
|
upb_arena* arena = upb_arena_new(); |
|
|
@ -61,9 +63,78 @@ static void BM_ParseDescriptor(benchmark::State& state) { |
|
|
|
} |
|
|
|
} |
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
} |
|
|
|
} |
|
|
|
BENCHMARK(BM_ParseDescriptor); |
|
|
|
BENCHMARK(BM_ParseDescriptor_Upb); |
|
|
|
|
|
|
|
|
|
|
|
static void BM_SerializeDescriptor(benchmark::State& state) { |
|
|
|
static void BM_ParseDescriptor_Proto2_NoArena(benchmark::State& state) { |
|
|
|
|
|
|
|
size_t bytes = 0; |
|
|
|
|
|
|
|
for (auto _ : state) { |
|
|
|
|
|
|
|
protobuf::FileDescriptorProto proto; |
|
|
|
|
|
|
|
protobuf::StringPiece input(descriptor.data,descriptor.size); |
|
|
|
|
|
|
|
bool ok = proto.ParseFrom<protobuf::MessageLite::kMergePartial>(input); |
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
|
|
|
|
printf("Failed to parse.\n"); |
|
|
|
|
|
|
|
exit(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bytes += descriptor.size; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BENCHMARK(BM_ParseDescriptor_Proto2_NoArena); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void BM_ParseDescriptor_Proto2_Arena(benchmark::State& state) { |
|
|
|
|
|
|
|
size_t bytes = 0; |
|
|
|
|
|
|
|
for (auto _ : state) { |
|
|
|
|
|
|
|
protobuf::Arena arena; |
|
|
|
|
|
|
|
protobuf::StringPiece input(descriptor.data,descriptor.size); |
|
|
|
|
|
|
|
auto proto = protobuf::Arena::CreateMessage<protobuf::FileDescriptorProto>( |
|
|
|
|
|
|
|
&arena); |
|
|
|
|
|
|
|
bool ok = proto->ParseFrom<protobuf::MessageLite::kMergePartial>(input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
|
|
|
|
printf("Failed to parse.\n"); |
|
|
|
|
|
|
|
exit(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bytes += descriptor.size; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BENCHMARK(BM_ParseDescriptor_Proto2_Arena); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void BM_ParseDescriptor_Proto2_Arena_LargeInitialBlock(benchmark::State& state) { |
|
|
|
|
|
|
|
size_t bytes = 0; |
|
|
|
|
|
|
|
protobuf::ArenaOptions opts; |
|
|
|
|
|
|
|
opts.initial_block = buf; |
|
|
|
|
|
|
|
opts.initial_block_size = sizeof(buf); |
|
|
|
|
|
|
|
for (auto _ : state) { |
|
|
|
|
|
|
|
protobuf::Arena arena(opts); |
|
|
|
|
|
|
|
protobuf::StringPiece input(descriptor.data,descriptor.size); |
|
|
|
|
|
|
|
auto proto = protobuf::Arena::CreateMessage<protobuf::FileDescriptorProto>( |
|
|
|
|
|
|
|
&arena); |
|
|
|
|
|
|
|
bool ok = proto->ParseFrom<protobuf::MessageLite::kMergePartial>(input); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
|
|
|
|
printf("Failed to parse.\n"); |
|
|
|
|
|
|
|
exit(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bytes += descriptor.size; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BENCHMARK(BM_ParseDescriptor_Proto2_Arena_LargeInitialBlock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void BM_SerializeDescriptor_Proto2(benchmark::State& state) { |
|
|
|
|
|
|
|
size_t bytes = 0; |
|
|
|
|
|
|
|
protobuf::FileDescriptorProto proto; |
|
|
|
|
|
|
|
proto.ParseFromArray(descriptor.data, descriptor.size); |
|
|
|
|
|
|
|
for (auto _ : state) { |
|
|
|
|
|
|
|
proto.SerializePartialToArray(buf, sizeof(buf)); |
|
|
|
|
|
|
|
bytes += descriptor.size; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
state.SetBytesProcessed(state.iterations() * descriptor.size); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BENCHMARK(BM_SerializeDescriptor_Proto2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void BM_SerializeDescriptor_Upb(benchmark::State& state) { |
|
|
|
int64_t total = 0; |
|
|
|
int64_t total = 0; |
|
|
|
upb_arena* arena = upb_arena_new(); |
|
|
|
upb_arena* arena = upb_arena_new(); |
|
|
|
google_protobuf_FileDescriptorProto* set = |
|
|
|
google_protobuf_FileDescriptorProto* set = |
|
|
@ -85,4 +156,4 @@ static void BM_SerializeDescriptor(benchmark::State& state) { |
|
|
|
} |
|
|
|
} |
|
|
|
state.SetBytesProcessed(total); |
|
|
|
state.SetBytesProcessed(total); |
|
|
|
} |
|
|
|
} |
|
|
|
BENCHMARK(BM_SerializeDescriptor); |
|
|
|
BENCHMARK(BM_SerializeDescriptor_Upb); |
|
|
|