pull/13171/head
Joshua Haberman 4 years ago
parent 7b8ae7ec4e
commit 4bd34da105
  1. 87
      benchmarks/BUILD
  2. 44
      benchmarks/build_defs.bzl
  3. 6
      benchmarks/empty.proto
  4. 4
      benchmarks/protobuf_binary.cc.tmpl
  5. 12
      benchmarks/upb_binary.c
  6. 12
      benchmarks/upb_binary.c.tmpl

@ -3,6 +3,11 @@ load(
"upb_proto_library",
"upb_proto_reflection_library",
)
load(
":build_defs.bzl",
"tmpl_cc_binary",
"cc_lite_proto_library",
)
licenses(["notice"])
@ -60,32 +65,76 @@ cc_binary(
# Size benchmarks.
upb_proto_library(
name = "empty_upb_proto",
deps = ["@com_google_protobuf//:empty_proto"],
SIZE_BENCHMARKS = {
"empty": "Empty",
"descriptor": "FileDescriptorSet",
"100_msgs": "Message99",
}
py_binary(
name = "gen_benchmark_proto",
srcs = ["gen_benchmark_proto.py"],
)
cc_proto_library(
name = "empty_cc_proto",
deps = ["@com_google_protobuf//:empty_proto"],
genrule(
name = "gen_100_msgs",
tools = [":gen_benchmark_proto"],
outs = ["100_msgs.proto"],
cmd = "$(execpath :gen_benchmark_proto) $@",
)
cc_binary(
name = "upb_binary",
[(
proto_library(
name = k + "_proto",
srcs = [k + ".proto"],
),
upb_proto_library(
name = k + "_upb_proto",
deps = [":" + k + "_proto"],
),
cc_proto_library(
name = k + "_cc_proto",
deps = [":" + k + "_proto"],
),
tmpl_cc_binary(
name = k + "_upb_binary",
testonly = 1,
srcs = ["upb_binary.c"],
srcs = ["upb_binary.c.tmpl"],
replacements = {
"PROTO": "upb_benchmark_" + v,
"INCLUDE": "benchmarks/" + k + ".upb.h",
},
deps = [
":empty_upb_proto",
":" + k + "_upb_proto",
],
#features = ["fully_static_link"],
)
cc_binary(
name = "protobuf_binary",
),
tmpl_cc_binary(
name = k + "_protobuf_binary",
testonly = 1,
srcs = ["protobuf_binary.cc"],
srcs = ["protobuf_binary.cc.tmpl"],
replacements = {
"PROTO": "upb_benchmark::" + v,
"INCLUDE": "benchmarks/" + k + ".pb.h",
},
deps = [
":empty_cc_proto",
":" + k + "_cc_proto",
],
#features = ["fully_static_link"],
)
),
cc_lite_proto_library(
srcs = [k + ".proto"],
outs = [k + "_lite.proto"],
name = k + "_cc_lite_proto",
),
tmpl_cc_binary(
name = k + "_lite_protobuf_binary",
testonly = 1,
srcs = ["protobuf_binary.cc.tmpl"],
replacements = {
"PROTO": "upb_benchmark::" + v,
"INCLUDE": "benchmarks/" + k + "_lite.pb.h",
},
deps = [
":" + k + "_cc_lite_proto",
],
)) for k, v in SIZE_BENCHMARKS.items()]

@ -0,0 +1,44 @@
def tmpl_cc_binary(name, srcs, replacements = [], **kwargs):
if len(srcs) != 1:
fail("Currently srcs must have exactly 1 element")
src = srcs[0]
if not src.endswith(".tmpl"):
fail("srcs of tmpl_cc_binary must end with .tmpl")
outs = [name + "_" + src[:-5]]
sed_cmds = ["s,{},{},g".format(k, v) for k, v in replacements.items()]
cmd = "sed -e '{}' $< > $@".format("; ".join(sed_cmds))
native.genrule(
name = name + "_gen_srcs",
srcs = [src],
outs = outs,
cmd = cmd,
)
native.cc_binary(
name = name,
srcs = outs,
**kwargs,
)
def cc_lite_proto_library(name, srcs, outs):
if len(srcs) != 1:
fail("Currently srcs must have exactly 1 element")
native.genrule(
name = name + "_gen_proto",
srcs = srcs,
outs = outs,
cmd = "cp $< $@ && chmod a+w $@ && echo 'option optimize_for = LITE_RUNTIME;' >> $@",
)
native.proto_library(
name = name + "_proto",
srcs = outs,
)
native.cc_proto_library(
name = name,
deps = [":" + name + "_proto"],
)

@ -0,0 +1,6 @@
syntax = "proto3";
package upb_benchmark;
message Empty {}

@ -1,10 +1,10 @@
#include "google/protobuf/empty.pb.h"
#include "INCLUDE"
char buf[1];
int main() {
google::protobuf::Empty proto;
PROTO proto;
proto.ParseFromArray(buf, 1);
proto.SerializeToArray(buf, 1);
}

@ -1,12 +0,0 @@
#include "google/protobuf/empty.upb.h"
char buf[1];
int main() {
upb_arena *arena = upb_arena_new();
size_t size;
google_protobuf_Empty *proto = google_protobuf_Empty_parse(buf, 1, arena);
google_protobuf_Empty_serialize(proto, arena, &size);
return 0;
}

@ -0,0 +1,12 @@
#include "INCLUDE"
char buf[1];
int main() {
upb_arena *arena = upb_arena_new();
size_t size;
PROTO *proto = PROTO_parse(buf, 1, arena);
PROTO_serialize(proto, arena, &size);
return 0;
}
Loading…
Cancel
Save