summaryrefslogtreecommitdiff
path: root/benchmark.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-07 01:10:20 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-07 01:10:20 -0700
commit137991c7b2def357b9f18d0cd01ba671ebf1392d (patch)
treeb0cbb542fc4eec2ad2aabc61fd163bdba51b6f9f /benchmark.c
parent34fe50818d9cfb7c6200875985f12546e9400f22 (diff)
Added the beginnings of a benchmark.
Diffstat (limited to 'benchmark.c')
-rw-r--r--benchmark.c49
1 files changed, 49 insertions, 0 deletions
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;
+ }
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback