|
|
|
@ -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++) { |
|
|
|
|