diff --git a/Makefile b/Makefile index f61d85b3e2..210f4ac73b 100644 --- a/Makefile +++ b/Makefile @@ -2,25 +2,26 @@ # Function to expand a wildcard pattern recursively. rwildcard=$(strip $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)$(filter $(subst *,%,$2),$d))) -.PHONY: all clean +.PHONY: all clean test benchmarks CC=gcc CXX=g++ CFLAGS=-std=c99 INCLUDE=-Idescriptor -Isrc -Itests -I. -CPPFLAGS=-O3 -fomit-frame-pointer -Wall -Wextra -g -DNDEBUG $(INCLUDE) +CPPFLAGS=-O3 -Wall -Wextra -g $(INCLUDE) $(strip $(shell cat perf-cppflags)) -ALL=deps $(OBJ) src/libupb.a tests/test_table tests/tests tools/upbc +LIBUPB=src/libupb.a +ALL=deps $(OBJ) $(LIBUPB) tests/test_table tests/tests tools/upbc all: $(ALL) clean: - rm -f $(call rwildcard,,*.o) $(ALL) benchmark/google_messages.proto.pb benchmark/google_messages.pb.* benchmark/b_* + rm -f $(call rwildcard,,*.o) $(ALL) benchmark/google_messages.proto.pb benchmark/google_messages.pb.* benchmarks/b.* benchmarks/*.pb* # The core library (src/libupb.a) OBJ=src/upb_parse.o src/upb_table.o src/upb_msg.o src/upb_enum.o src/upb_context.o \ src/upb_string.o src/upb_text.o src/upb_serialize.o descriptor/descriptor.o SRC=$(call rwildcard,,*.c) HEADERS=$(call rwildcard,,*.h) -src/libupb.a: $(OBJ) - ar rcs src/libupb.a $(OBJ) +$(LIBUPB): $(OBJ) + ar rcs $(LIBUPB) $(OBJ) # Tests test: tests/tests @@ -32,6 +33,77 @@ tests/tests: src/libupb.a tools/upbc: src/libupb.a # Benchmarks +BENCHMARKS=benchmarks/b.parsetostruct_googlemessage1.upb_table_byval \ + benchmarks/b.parsetostruct_googlemessage1.upb_table_byref \ + benchmarks/b.parsetostruct_googlemessage2.upb_table_byval \ + benchmarks/b.parsetostruct_googlemessage2.upb_table_byref \ + benchmarks/b.parsetostruct_googlemessage1.proto2_table \ + benchmarks/b.parsetostruct_googlemessage2.proto2_table \ + benchmarks/b.parsetostruct_googlemessage1.proto2_compiled \ + benchmarks/b.parsetostruct_googlemessage2.proto2_compiled +benchmarks: $(BENCHMARKS) + +benchmarks/google_messages.proto.pb: benchmarks/google_messages.proto + # TODO: replace with upbc. + protoc benchmarks/google_messages.proto -obenchmarks/google_messages.proto.pb + +benchmarks/google_messages.pb.cc: benchmarks/google_messages.proto + protoc benchmarks/google_messages.proto --cpp_out=. + +benchmarks/b.parsetostruct_googlemessage1.upb_table_byval \ +benchmarks/b.parsetostruct_googlemessage1.upb_table_byref \ +benchmarks/b.parsetostruct_googlemessage2.upb_table_byval \ +benchmarks/b.parsetostruct_googlemessage2.upb_table_byref: \ + benchmarks/parsetostruct.upb_table.c $(LIBUPB) benchmarks/google_messages.proto.pb + $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage1.upb_table_byval $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message1.dat\" \ + -DBYREF=false $(LIBUPB) + $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage1.upb_table_byref $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message1.dat\" \ + -DBYREF=true $(LIBUPB) + $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage2.upb_table_byval $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message2.dat\" \ + -DBYREF=false $(LIBUPB) + $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage2.upb_table_byref $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message2.dat\" \ + -DBYREF=true $(LIBUPB) + +benchmarks/b.parsetostruct_googlemessage1.proto2_table \ +benchmarks/b.parsetostruct_googlemessage2.proto2_table: \ + benchmarks/parsetostruct.proto2_table.cc benchmarks/google_messages.pb.cc + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage1.proto2_table $< \ + -DMESSAGE_CIDENT="benchmarks::SpeedMessage1" \ + -DMESSAGE_FILE=\"google_message1.dat\" \ + -DMESSAGE_HFILE=\"google_messages.pb.h\" \ + benchmarks/google_messages.pb.cc -lprotobuf -lpthread + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage2.proto2_table $< \ + -DMESSAGE_CIDENT="benchmarks::SpeedMessage2" \ + -DMESSAGE_FILE=\"google_message2.dat\" \ + -DMESSAGE_HFILE=\"google_messages.pb.h\" \ + benchmarks/google_messages.pb.cc -lprotobuf -lpthread + +benchmarks/b.parsetostruct_googlemessage1.proto2_compiled \ +benchmarks/b.parsetostruct_googlemessage2.proto2_compiled: \ + benchmarks/parsetostruct.proto2_compiled.cc \ + benchmarks/parsetostruct.proto2_table.cc benchmarks/google_messages.pb.cc + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage1.proto2_compiled $< \ + -DMESSAGE_CIDENT="benchmarks::SpeedMessage1" \ + -DMESSAGE_FILE=\"google_message1.dat\" \ + -DMESSAGE_HFILE=\"google_messages.pb.h\" \ + benchmarks/google_messages.pb.cc -lprotobuf -lpthread + $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage2.proto2_compiled $< \ + -DMESSAGE_CIDENT="benchmarks::SpeedMessage2" \ + -DMESSAGE_FILE=\"google_message2.dat\" \ + -DMESSAGE_HFILE=\"google_messages.pb.h\" \ + benchmarks/google_messages.pb.cc -lprotobuf -lpthread -include deps deps: $(SRC) $(HEADERS) gen-deps.sh Makefile diff --git a/benchmark/gen.sh b/benchmark/gen.sh deleted file mode 100755 index 288071eb23..0000000000 --- a/benchmark/gen.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -cd `dirname $0` -CXXFLAGS="-O3 -msse3 -I../src -I../descriptor -Wall" -CFLAGS="-std=c99 $CXXFLAGS" -set -e -set -v - -gcc -DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \ - -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ - -DMESSAGE_FILE=\"google_message1.dat\" \ - -DBYREF=false \ - $CFLAGS \ - parsetostruct_upb_table.c -o b_parsetostruct_googlemessage1_upb_table_byval ../src/libupb.a - -gcc -DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \ - -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ - -DMESSAGE_FILE=\"google_message1.dat\" \ - -DBYREF=true \ - $CFLAGS \ - parsetostruct_upb_table.c -o b_parsetostruct_googlemessage1_upb_table_byref ../src/libupb.a - -gcc -DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \ - -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ - -DMESSAGE_FILE=\"google_message2.dat\" \ - -DBYREF=false \ - $CFLAGS \ - parsetostruct_upb_table.c -o b_parsetostruct_googlemessage2_upb_table_byval ../src/libupb.a - -gcc -DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \ - -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ - -DMESSAGE_FILE=\"google_message2.dat\" \ - -DBYREF=true \ - $CFLAGS \ - parsetostruct_upb_table.c -o b_parsetostruct_googlemessage2_upb_table_byref ../src/libupb.a - -g++ -DMESSAGE_CIDENT="benchmarks::SpeedMessage2" \ - -DMESSAGE_FILE=\"google_message2.dat\" \ - -DMESSAGE_HFILE=\"google_messages.pb.h\" \ - $CXXFLAGS \ - parsetostruct_proto2_table.cc -o b_parsetostruct_googlemessage2_proto2_table -lprotobuf -lpthread google_messages.pb.o - -g++ -DMESSAGE_CIDENT="benchmarks::SpeedMessage2" \ - -DMESSAGE_FILE=\"google_message2.dat\" \ - -DMESSAGE_HFILE=\"google_messages.pb.h\" \ - $CXXFLAGS \ - parsetostruct_proto2_compiled.cc -o b_parsetostruct_googlemessage2_proto2_compiled -lprotobuf -lpthread google_messages.pb.o - -g++ -DMESSAGE_CIDENT="benchmarks::SpeedMessage1" \ - -DMESSAGE_FILE=\"google_message1.dat\" \ - -DMESSAGE_HFILE=\"google_messages.pb.h\" \ - $CXXFLAGS \ - parsetostruct_proto2_table.cc -o b_parsetostruct_googlemessage1_proto2_table -lprotobuf -lpthread google_messages.pb.o - -g++ -DMESSAGE_CIDENT="benchmarks::SpeedMessage1" \ - -DMESSAGE_FILE=\"google_message1.dat\" \ - -DMESSAGE_HFILE=\"google_messages.pb.h\" \ - $CXXFLAGS \ - parsetostruct_proto2_compiled.cc -o b_parsetostruct_googlemessage1_proto2_compiled -lprotobuf -lpthread google_messages.pb.o diff --git a/benchmark/getgraphs.py b/benchmarks/getgraphs.py similarity index 98% rename from benchmark/getgraphs.py rename to benchmarks/getgraphs.py index 392b6efbf7..aacf6b2d19 100644 --- a/benchmark/getgraphs.py +++ b/benchmarks/getgraphs.py @@ -26,7 +26,7 @@ for benchmark, values in benchmarks.items(): values.sort(cmp) variants = [x[0] for x in values] values = [x[1] for x in values] - scaling = 300 + scaling = 400 encoded_values = [encode((x * 4096 / scaling) - 1) for x in values] legend = "chdl=%s" % ("|".join(variants)) colors = "chco=%s" % ("|".join([color_map[x] for x in variants])) diff --git a/benchmark/google_message1.dat b/benchmarks/google_message1.dat similarity index 100% rename from benchmark/google_message1.dat rename to benchmarks/google_message1.dat diff --git a/benchmark/google_message2.dat b/benchmarks/google_message2.dat similarity index 100% rename from benchmark/google_message2.dat rename to benchmarks/google_message2.dat diff --git a/benchmark/google_messages.proto b/benchmarks/google_messages.proto similarity index 100% rename from benchmark/google_messages.proto rename to benchmarks/google_messages.proto diff --git a/benchmark/main.c b/benchmarks/main.c similarity index 64% rename from benchmark/main.c rename to benchmarks/main.c index c0382878b3..f66b4d0598 100644 --- a/benchmark/main.c +++ b/benchmarks/main.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include static bool initialize(); static void cleanup(); @@ -9,6 +11,18 @@ static size_t run(); int main (int argc, char *argv[]) { + (void)argc; + + /* Change cwd to where the binary is. */ + char *lastslash = strrchr(argv[0], '/'); + char *progname = argv[0]; + if(lastslash) { + *lastslash = '\0'; + chdir(argv[0]); + *lastslash = '/'; + progname = lastslash + 3; /* "/b_" */ + } + if(!initialize()) { fprintf(stderr, "%s: failed to initialize\n", argv[0]); return 1; @@ -26,7 +40,7 @@ int main (int argc, char *argv[]) total_bytes += bytes; } double elapsed = ((double)clock() - before) / CLOCKS_PER_SEC; - printf("%s: %d\n", argv[0], (int)(total_bytes / elapsed / (1 << 20))); + printf("%s:%d\n", progname, (int)(total_bytes / elapsed / (1 << 20))); cleanup(); return 0; } diff --git a/benchmark/parsetostruct_proto2_compiled.cc b/benchmarks/parsetostruct.proto2_compiled.cc similarity index 100% rename from benchmark/parsetostruct_proto2_compiled.cc rename to benchmarks/parsetostruct.proto2_compiled.cc diff --git a/benchmark/parsetostruct_proto2_table.cc b/benchmarks/parsetostruct.proto2_table.cc similarity index 100% rename from benchmark/parsetostruct_proto2_table.cc rename to benchmarks/parsetostruct.proto2_table.cc diff --git a/benchmark/parsetostruct_upb_table.c b/benchmarks/parsetostruct.upb_table.c similarity index 100% rename from benchmark/parsetostruct_upb_table.c rename to benchmarks/parsetostruct.upb_table.c diff --git a/perf-cppflags b/perf-cppflags new file mode 100644 index 0000000000..a8d2641e41 --- /dev/null +++ b/perf-cppflags @@ -0,0 +1 @@ +-DNDEBUG -fomit-frame-pointer