diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2011-08-17 08:15:57 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2011-08-17 08:15:57 -0700 |
commit | fa82e4fbf065bb474b0f87023f66edffb8a5b850 (patch) | |
tree | e515ba7d9a431a05b08468619b8289d7bc9b1527 | |
parent | 51d4e295a4d8e55facf0e95502cde75d488fd511 (diff) |
Benchmark JIT vs no JIT without forcing a whole-project recompile.
-rw-r--r-- | Makefile | 98 | ||||
-rw-r--r-- | benchmarks/parsestream.upb.c (renamed from benchmarks/parsestream.upb_table.c) | 1 | ||||
-rw-r--r-- | benchmarks/parsetostruct.upb.c (renamed from benchmarks/parsetostruct.upb_table.c) | 6 | ||||
-rwxr-xr-x | perf-tests.sh | 7 |
4 files changed, 75 insertions, 37 deletions
@@ -35,6 +35,13 @@ ifeq (, $(findstring -O, $(USER_CFLAGS))) DEF_OPT = -Os endif +ifneq (, $(findstring DUPB_USE_JIT_X64, $(USER_CFLAGS))) + ifeq (, $(findstring DNDEBUG, $(USER_CFLAGS))) + $(error "JIT only works with -DNDEBUG enabled!") + endif + USE_JIT=true +endif + # Basic compiler/flag setup. CC=gcc CXX=g++ @@ -91,8 +98,8 @@ OTHERSRC=upb/pb/encoder.c BENCHMARKS_SRC= \ benchmarks/main.c \ - benchmarks/parsestream.upb_table.c \ - benchmarks/parsetostruct.upb_table.c + benchmarks/parsestream.upb.c \ + benchmarks/parsetostruct.upb.c TESTS_SRC= \ tests/test_decoder.c \ @@ -135,11 +142,8 @@ lib: $(LIBUPB) OBJ=$(patsubst %.c,%.o,$(SRC)) PICOBJ=$(patsubst %.c,%.lo,$(SRC)) -ifneq (, $(findstring DUPB_USE_JIT_X64, $(USER_CFLAGS))) +ifdef USE_JIT upb/pb/decoder.o upb/pb/decoder.lo: upb/pb/decoder_x86.h - ifeq (, $(findstring DNDEBUG, $(USER_CFLAGS))) - $(error "JIT only works with -DNDEBUG enabled!") - endif endif $(LIBUPB): $(OBJ) $(E) AR $(LIBUPB) @@ -277,8 +281,16 @@ tests/tests: upb/libupb.a # Benchmarks UPB_BENCHMARKS=benchmarks/b.parsestream_googlemessage1.upb_table \ benchmarks/b.parsestream_googlemessage2.upb_table \ - benchmarks/b.parsetostruct_googlemessage1.upb_table_byref \ - benchmarks/b.parsetostruct_googlemessage2.upb_table_byref + benchmarks/b.parsetostruct_googlemessage1.upb_table_byval \ + benchmarks/b.parsetostruct_googlemessage2.upb_table_byval \ + +ifdef USE_JIT +UPB_BENCHMARKS += \ + benchmarks/b.parsestream_googlemessage1.upb_jit \ + benchmarks/b.parsestream_googlemessage2.upb_jit \ + benchmarks/b.parsetostruct_googlemessage1.upb_jit_byval \ + benchmarks/b.parsetostruct_googlemessage2.upb_jit_byval +endif BENCHMARKS=$(UPB_BENCHMARKS) \ benchmarks/b.parsetostruct_googlemessage1.proto2_table \ @@ -300,51 +312,71 @@ 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 - $(E) 'CC benchmarks/parsetostruct.upb_table.c (benchmarks.SpeedMessage1, byval)' +benchmarks/b.parsetostruct_googlemessage2.upb_table_byval: \ + benchmarks/parsetostruct.upb.c $(LIBUPB) benchmarks/google_messages.proto.pb + $(E) 'CC benchmarks/parsetostruct.upb.c (benchmarks.SpeedMessage1, byval, nojit)' $(Q) $(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) - $(E) 'CC benchmarks/parsetostruct.upb_table.c (benchmarks.SpeedMessage1, byref)' - $(Q) $(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) - $(E) 'CC benchmarks/parsetostruct.upb_table.c (benchmarks.SpeedMessage2, byval)' + -DBYREF=false -DJIT=false $(LIBUPB) + $(E) 'CC benchmarks/parsetostruct.upb.c (benchmarks.SpeedMessage2, byref, nojit)' $(Q) $(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) - $(E) 'CC benchmarks/parsetostruct.upb_table.c (benchmarks.SpeedMessage2, byref)' - $(Q) $(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) + -DBYREF=false -DJIT=false $(LIBUPB) benchmarks/b.parsestream_googlemessage1.upb_table \ benchmarks/b.parsestream_googlemessage2.upb_table: \ - benchmarks/parsestream.upb_table.c $(LIBUPB) benchmarks/google_messages.proto.pb - $(E) 'CC benchmarks/parsestream.upb_table.c (benchmarks.SpeedMessage1)' + benchmarks/parsestream.upb.c $(LIBUPB) benchmarks/google_messages.proto.pb + $(E) 'CC benchmarks/parsestream.upb.c (benchmarks.SpeedMessage1, nojit)' $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsestream_googlemessage1.upb_table $< \ -DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \ -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ - -DMESSAGE_FILE=\"google_message1.dat\" \ + -DMESSAGE_FILE=\"google_message1.dat\" -DJIT=false \ $(LIBUPB) - $(E) 'CC benchmarks/parsestream.upb_table.c (benchmarks.SpeedMessage2)' + $(E) 'CC benchmarks/parsestream.upb.c (benchmarks.SpeedMessage2, nojit)' $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsestream_googlemessage2.upb_table $< \ -DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \ -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ - -DMESSAGE_FILE=\"google_message2.dat\" \ + -DMESSAGE_FILE=\"google_message2.dat\" -DJIT=false \ $(LIBUPB) +ifdef USE_JIT +benchmarks/b.parsetostruct_googlemessage1.upb_jit_byval \ +benchmarks/b.parsetostruct_googlemessage2.upb_jit_byval: \ + benchmarks/parsetostruct.upb.c $(LIBUPB) benchmarks/google_messages.proto.pb + $(E) 'CC benchmarks/parsetostruct.upb.c (benchmarks.SpeedMessage1, byref, jit)' + $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage1.upb_jit_byval $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message1.dat\" -DJIT=true \ + -DBYREF=true -DJIT=true $(LIBUPB) + $(E) 'CC benchmarks/parsetostruct.upb.c (benchmarks.SpeedMessage2, byval, jit)' + $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsetostruct_googlemessage2.upb_jit_byval $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message2.dat\" -DJIT=true \ + -DBYREF=false -DJIT=true $(LIBUPB) + +benchmarks/b.parsestream_googlemessage1.upb_jit \ +benchmarks/b.parsestream_googlemessage2.upb_jit: \ + benchmarks/parsestream.upb.c $(LIBUPB) benchmarks/google_messages.proto.pb + $(E) 'CC benchmarks/parsestream.upb.c (benchmarks.SpeedMessage1, jit)' + $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsestream_googlemessage1.upb_jit $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message1.dat\" -DJIT=true \ + $(LIBUPB) + $(E) 'CC benchmarks/parsestream.upb.c (benchmarks.SpeedMessage2, jit)' + $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -o benchmarks/b.parsestream_googlemessage2.upb_jit $< \ + -DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \ + -DMESSAGE_DESCRIPTOR_FILE=\"google_messages.proto.pb\" \ + -DMESSAGE_FILE=\"google_message2.dat\" -DJIT=true \ + $(LIBUPB) +endif + benchmarks/b.parsetostruct_googlemessage1.proto2_table \ benchmarks/b.parsetostruct_googlemessage2.proto2_table: \ benchmarks/parsetostruct.proto2_table.cc benchmarks/google_messages.pb.cc diff --git a/benchmarks/parsestream.upb_table.c b/benchmarks/parsestream.upb.c index a4022b1..37ccb42 100644 --- a/benchmarks/parsestream.upb_table.c +++ b/benchmarks/parsestream.upb.c @@ -52,6 +52,7 @@ static bool initialize() } upb_handlers *handlers = upb_handlers_new(); + if (!JIT) handlers->should_jit = false; // Cause all messages to be read, but do nothing when they are. upb_handlerset hset = {NULL, NULL, value, startsubmsg, NULL, NULL, NULL}; upb_handlers_reghandlerset(handlers, def, &hset); diff --git a/benchmarks/parsetostruct.upb_table.c b/benchmarks/parsetostruct.upb.c index 88f355d..a436fd4 100644 --- a/benchmarks/parsetostruct.upb_table.c +++ b/benchmarks/parsetostruct.upb.c @@ -42,7 +42,11 @@ static bool initialize() upb_stringsrc_init(&strsrc); upb_stringsrc_reset(&strsrc, str, len); - upb_decoder_initformsgdef(&d, def); + upb_handlers *h = upb_handlers_new(); + upb_accessors_reghandlers(h, def); + if (!JIT) h->should_jit = false; + upb_decoder_initforhandlers(&d, h); + upb_handlers_unref(h); if (!BYREF) { // TODO: use byref/byval accessors. diff --git a/perf-tests.sh b/perf-tests.sh index 118922d..7bdbee0 100755 --- a/perf-tests.sh +++ b/perf-tests.sh @@ -26,6 +26,7 @@ run_with_flags () { run_with_flags "-DNDEBUG -fomit-frame-pointer -m32" "omitfp32" #fi -run_with_flags "-DNDEBUG " "plain" -run_with_flags "-DNDEBUG -fomit-frame-pointer" "omitfp" -run_with_flags "-DNDEBUG -DUPB_USE_JIT_X64" "jit" +# Ideally we could test for x86-64 in deciding whether to compile with +# the JIT flag. +run_with_flags "-DNDEBUG -DUPB_USE_JIT_X64" "plain" +run_with_flags "-DNDEBUG -fomit-frame-pointer -DUPB_USE_JIT_X64" "omitfp" |