diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-07-24 17:31:37 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-07-24 17:31:37 -0700 |
commit | b39b463ec9b2fba7440050c4508429cf42c543d4 (patch) | |
tree | bf826a40ab6ed1b42924f6bae7e4e755e4046096 | |
parent | 413ccaf6b9e44efbee7ddcd7c1abc6c246e10191 (diff) |
Add proto2 dynamic message to benchmark.
-rw-r--r-- | benchmark/benchmark.cc | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/benchmark/benchmark.cc b/benchmark/benchmark.cc index 10713a8..c3f2f6e 100644 --- a/benchmark/benchmark.cc +++ b/benchmark/benchmark.cc @@ -1,12 +1,14 @@ #include <time.h> #include "google_messages.pb.h" +#include <google/protobuf/dynamic_message.h> #include "test_util.h" #include "upb_context.h" #include "upb_msg.h" int main () { + /* Initialize upb state, parse descriptor. */ struct upb_context c; upb_context_init(&c); struct upb_string fds; @@ -30,6 +32,7 @@ int main () return 1; } + /* upb speed test, copying string. */ struct upb_msg *m = e->ref.msg; struct upb_msg_parse_state s; void *data = upb_msgdata_new(m); @@ -55,6 +58,7 @@ int main () fprintf(stderr, "upb parsed %sB, ", eng(total, 3, false)); fprintf(stderr, "%sB/s\n", eng(total/elapsed, 3, false)); + /* upb speed test, referencing strings. */ total = 0; before = clock(); for(int i = 0; i < 2000; i++) { @@ -73,9 +77,29 @@ int main () upb_msgdata_free(data, m, true); upb_context_free(&c); - benchmarks::SpeedMessage2 msg; + /* proto2 speed test, dynamic type. */ std::string stlstr(str.ptr, str.byte_len); upb_strfree(str); + + google::protobuf::DynamicMessageFactory factory; + const google::protobuf::Message *dynamic_msg_prototype = factory.GetPrototype(benchmarks::SpeedMessage2::descriptor()); + google::protobuf::Message *dynamic_msg = dynamic_msg_prototype->New(); + total = 0; + before = clock(); + for(int i = 0; i < 2000; i++) { + if(!dynamic_msg->ParseFromString(stlstr)) { + fprintf(stderr, "Error parsing with proto2.\n"); + return 1; + } + total += str.byte_len; + } + delete dynamic_msg; + elapsed = ((double)clock() - before) / CLOCKS_PER_SEC; + fprintf(stderr, "proto2(dynamic) parsed %sB, ", eng(total, 3, false)); + fprintf(stderr, "%sB/s\n", eng(total/elapsed, 3, false)); + + /* proto2 speed test, compiled-in type. */ + benchmarks::SpeedMessage2 msg; total = 0; before = clock(); for(int i = 0; i < 2000; i++) { |