diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2019-06-02 22:02:04 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2019-06-02 22:02:04 -0700 |
commit | e1f84aeb10e526aab986351fa5eb4c944d0f6e7b (patch) | |
tree | 69ee5f5c4a382cea625e31993bfad7a3c111abff /tests/benchmark.cc | |
parent | 7485261370ad0bb691c801a4128712d962cdd7d3 (diff) | |
parent | 00e739648d816fae3972c9d51fef24940cf50539 (diff) |
Merge branch 'master' into rmreflective
Diffstat (limited to 'tests/benchmark.cc')
-rw-r--r-- | tests/benchmark.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/benchmark.cc b/tests/benchmark.cc new file mode 100644 index 0000000..bcb4ec7 --- /dev/null +++ b/tests/benchmark.cc @@ -0,0 +1,36 @@ + +#include <string.h> +#include <benchmark/benchmark.h> +#include "google/protobuf/descriptor.upb.h" +#include "google/protobuf/descriptor.upbdefs.h" + +upb_strview descriptor = google_protobuf_descriptor_proto_upbdefinit.descriptor; + +/* A buffer big enough to parse descriptor.proto without going to heap. */ +char buf[65535]; + +static void BM_CreateArena(benchmark::State& state) { + for (auto _ : state) { + upb_arena* arena = upb_arena_init(buf, sizeof(buf), NULL); + upb_arena_free(arena); + } +} +BENCHMARK(BM_CreateArena); + +static void BM_ParseDescriptor(benchmark::State& state) { + size_t bytes = 0; + for (auto _ : state) { + upb_arena* arena = upb_arena_init(buf, sizeof(buf), NULL); + google_protobuf_FileDescriptorProto* set = + google_protobuf_FileDescriptorProto_parse(descriptor.data, + descriptor.size, arena); + if (!set) { + printf("Failed to parse.\n"); + exit(1); + } + bytes += descriptor.size; + upb_arena_free(arena); + } + state.SetBytesProcessed(state.iterations() * descriptor.size); +} +BENCHMARK(BM_ParseDescriptor); |