diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2019-06-02 22:01:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-02 22:01:30 -0700 |
commit | 00e739648d816fae3972c9d51fef24940cf50539 (patch) | |
tree | 116cb839d56d1bd9a7053e3d27569b2da08475d9 | |
parent | 26245628a9b8abfc217b080eec73af477a5fc65c (diff) | |
parent | 901463e41e0ef32266a59b5ba4a63c94529c86bd (diff) |
Merge pull request #179 from haberman/benchmark
Added benchmark of parsing.
-rw-r--r-- | BUILD | 11 | ||||
-rw-r--r-- | WORKSPACE | 14 | ||||
-rw-r--r-- | tests/benchmark.cc | 36 |
3 files changed, 61 insertions, 0 deletions
@@ -249,6 +249,17 @@ cc_binary( # C/C++ tests ################################################################## +cc_binary( + name = "benchmark", + testonly = 1, + srcs = ["tests/benchmark.cc"], + deps = [ + ":descriptor_upbproto", + ":descriptor_upbreflection", + "@com_github_google_benchmark//:benchmark_main", + ], +) + cc_library( name = "upb_test", testonly = 1, @@ -23,3 +23,17 @@ http_archive( strip_prefix = "ragel-6.10", urls = ["http://www.colm.net/files/ragel/ragel-6.10.tar.gz"], ) + +http_archive( + name = "com_google_googletest", + urls = ["https://github.com/google/googletest/archive/b6cd405286ed8635ece71c72f118e659f4ade3fb.zip"], # 2019-01-07 + strip_prefix = "googletest-b6cd405286ed8635ece71c72f118e659f4ade3fb", + sha256 = "ff7a82736e158c077e76188232eac77913a15dac0b22508c390ab3f88e6d6d86", +) + +http_archive( + name = "com_github_google_benchmark", + urls = ["https://github.com/google/benchmark/archive/16703ff83c1ae6d53e5155df3bb3ab0bc96083be.zip"], + strip_prefix = "benchmark-16703ff83c1ae6d53e5155df3bb3ab0bc96083be", + sha256 = "59f918c8ccd4d74b6ac43484467b500f1d64b40cc1010daa055375b322a43ba3", +) 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); |