From 137991c7b2def357b9f18d0cd01ba671ebf1392d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 Jul 2009 01:10:20 -0700 Subject: Added the beginnings of a benchmark. --- Makefile | 3 +- benchmark.c | 49 +++++++++++++++++ google_message1.dat | Bin 0 -> 228 bytes google_message2.dat | Bin 0 -> 84570 bytes google_messages.proto.bin | 130 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 benchmark.c create mode 100644 google_message1.dat create mode 100644 google_message2.dat create mode 100644 google_messages.proto.bin diff --git a/Makefile b/Makefile index 8ddcd09..4643903 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC=gcc CXX=g++ CFLAGS=-std=c99 -CPPFLAGS=-Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK -fomit-frame-pointer +CPPFLAGS=-O0 -Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK OBJ=upb_parse.o upb_table.o upb_msg.o upb_enum.o upb_context.o upb_string.o descriptor.o all: $(OBJ) test_table tests upbc clean: @@ -13,6 +13,7 @@ libupb.a: $(OBJ) ar rcs libupb.a $(OBJ) test_table: libupb.a upbc: libupb.a +benchmark: libupb.a -include deps deps: *.c *.h diff --git a/benchmark.c b/benchmark.c new file mode 100644 index 0000000..03d8456 --- /dev/null +++ b/benchmark.c @@ -0,0 +1,49 @@ + +#include "upb_context.h" +#include "upb_msg.h" + +int main () +{ + struct upb_context c; + upb_context_init(&c); + struct upb_string fds; + if(!upb_strreadfile("google_speed.proto.bin", &fds)) { + fprintf(stderr, "Couldn't read google_speed.proto.bin.\n"); + return 1; + } + if(!upb_context_parsefds(&c, &fds)) { + fprintf(stderr, "Error parsing or resolving proto.\n"); + return 1; + } + upb_strfree(fds); + struct upb_string proto_name = UPB_STRLIT("benchmarks.SpeedMessage2"); + struct upb_symtab_entry *e = upb_context_lookup(&c, &proto_name); + if(!e || e->type != UPB_SYM_MESSAGE) { + fprintf(stderr, "Error finding symbol '" UPB_STRFMT "'.\n", + UPB_STRARG(proto_name)); + return 1; + } + + struct upb_msg *m = e->ref.msg; + struct upb_msg_parse_state s; + void *data = upb_msgdata_new(m); + upb_msg_parse_init(&s, data, m, false, true); + size_t read; + struct upb_string str; + if(!upb_strreadfile("google_message2.dat", &str)) { + fprintf(stderr, "Error reading google_message2.dat\n"); + return 1; + } + upb_status_t status = upb_msg_parse(&s, str.ptr, str.byte_len, &read); + upb_msg_parse_free(&s); + upb_msgdata_free(data, m, true); + upb_context_free(&c); + upb_strfree(str); + if(status == UPB_STATUS_OK && read == str.byte_len) { + fprintf(stderr, "Success!\n"); + return 0; + } else { + fprintf(stderr, "Error. :( error=%d, read=%d\n", status, read); + return 1; + } +} diff --git a/google_message1.dat b/google_message1.dat new file mode 100644 index 0000000..bc0f064 Binary files /dev/null and b/google_message1.dat differ diff --git a/google_message2.dat b/google_message2.dat new file mode 100644 index 0000000..06c0944 Binary files /dev/null and b/google_message2.dat differ diff --git a/google_messages.proto.bin b/google_messages.proto.bin new file mode 100644 index 0000000..0531d7e --- /dev/null +++ b/google_messages.proto.bin @@ -0,0 +1,130 @@ + +ï +google_speed.proto +benchmarks"ø + SpeedMessage1 +field1 (  +field9 (  +field18 (  +field80P (:false +field81Q (:true +field2 ( +field3 ( +field280˜ ( +field6 (:0 +field22 ( +field4 (  +field5 ( +field59; (:false +field7 (  +field16 ( +field130‚ (:0 +field12 (:true +field17 (:true +field13 (:true +field14 (:true +field104h (:0 +field100d (:0 +field101e (:0 +field102f (  +field103g (  +field29 (:0 +field30 (:false +field60< (:-1 +field271 (:-1 +field272 (:-1 +field150– ( +field23 (:0 +field24 (:false +field25 (:04 +field15 ( 2#.benchmarks.SpeedMessage1SubMessage +field78N ( +field67C (:0 +field68D ( +field128€ (:0( +field129 ( :xxxxxxxxxxxxxxxxxxxxx +field131ƒ (:0"¢ +SpeedMessage1SubMessage +field1 (:0 +field2 (:0 +field3 (:0 +field15 (  +field12 (:true +field13 ( +field14 ( +field16 ( +field19 (:2 +field20 (:true +field28 (:true +field21 ( +field22 ( +field23 (:false +field206Î (:false +field203Ë ( +field204Ì ( +field205Í (  +field207Ï ( +field300¬ ("Ê + SpeedMessage2 +field1 (  +field3 ( +field4 ( +field30 ( +field75K (:false +field6 (  +field2 (  +field21 (:0 +field71G ( +field25 ( +field109m (:0 +field210Ò (:0 +field211Ó (:0 +field212Ô (:0 +field213Õ (:0 +field216Ø (:0 +field217Ù (:0 +field218Ú (:0 +field220Ü (:0 +field221Ý (:0 +field222Þ (:0 +field63? (0 +group1 + ( +2 .benchmarks.SpeedMessage2.Group1 +field128€ (  +field131ƒ ( +field127 (  +field129 ( +field130‚ ( +field205Í (:false +field206Î (:falseà +Group1 +field11 ( +field26 ( +field12 (  +field13 (  +field14 (  +field15 ( +field5 ( +field27 (  +field28 ( +field29 (  +field16 (  +field22 (  +field73I ( +field20 (:0 +field24 ( 8 +field31 ( 2'.benchmarks.SpeedMessage2GroupedMessage"ß +SpeedMessage2GroupedMessage +field1 ( +field2 ( +field3 (:0 +field4 ( +field5 ( +field6 (:true +field7 (:false +field8 ( +field9 ( +field10 + ( +field11 ( \ No newline at end of file -- cgit v1.2.3