From b39b463ec9b2fba7440050c4508429cf42c543d4 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 24 Jul 2009 17:31:37 -0700 Subject: Add proto2 dynamic message to benchmark. --- benchmark/benchmark.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 #include "google_messages.pb.h" +#include #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++) { -- cgit v1.2.3