mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
5 years ago
|
|
||
|
#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];
|
||
|
|
||
5 years ago
|
static void BM_ArenaOneAlloc(benchmark::State& state) {
|
||
|
for (auto _ : state) {
|
||
|
upb_arena* arena = upb_arena_new();
|
||
|
upb_arena_malloc(arena, 1);
|
||
|
upb_arena_free(arena);
|
||
|
}
|
||
|
}
|
||
|
BENCHMARK(BM_ArenaOneAlloc);
|
||
|
|
||
|
static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) {
|
||
5 years ago
|
for (auto _ : state) {
|
||
|
upb_arena* arena = upb_arena_init(buf, sizeof(buf), NULL);
|
||
5 years ago
|
upb_arena_malloc(arena, 1);
|
||
5 years ago
|
upb_arena_free(arena);
|
||
|
}
|
||
|
}
|
||
5 years ago
|
BENCHMARK(BM_ArenaInitialBlockOneAlloc);
|
||
5 years ago
|
|
||
5 years ago
|
static void BM_ParseDescriptorNoHeap(benchmark::State& state) {
|
||
5 years ago
|
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);
|
||
|
}
|
||
5 years ago
|
BENCHMARK(BM_ParseDescriptorNoHeap);
|
||
|
|
||
|
static void BM_ParseDescriptor(benchmark::State& state) {
|
||
|
size_t bytes = 0;
|
||
|
for (auto _ : state) {
|
||
|
upb_arena* arena = upb_arena_new();
|
||
|
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);
|
||
|
}
|
||
5 years ago
|
BENCHMARK(BM_ParseDescriptor);
|