From 797bd11247fb0d5774b3fd6d9d562eaa5f8b14ae Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 Jul 2009 23:48:37 -0700 Subject: [PATCH] Made benchmark test proto2 also. --- benchmark.c => benchmark.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) rename benchmark.c => benchmark.cc (59%) diff --git a/benchmark.c b/benchmark.cc similarity index 59% rename from benchmark.c rename to benchmark.cc index aede9d333e..05184bc28c 100644 --- a/benchmark.c +++ b/benchmark.cc @@ -1,4 +1,6 @@ +#include +#include "google_speed.pb.h" #include "test_util.h" #include "upb_context.h" #include "upb_msg.h" @@ -17,7 +19,10 @@ int main () return 1; } upb_strfree(fds); - struct upb_string proto_name = UPB_STRLIT("benchmarks.SpeedMessage2"); + char class_name[] = "benchmarks.SpeedMessage2"; + struct upb_string proto_name; + proto_name.ptr = class_name; + proto_name.byte_len = sizeof(class_name)-1; 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", @@ -36,18 +41,32 @@ int main () return 1; } size_t total = 0; - for(int i = 0; i < 1000; i++) { + clock_t before = clock(); + for(int i = 0; i < 2000; i++) { upb_msg_parse_reset(&s, data, m, false, true); upb_status_t status = upb_msg_parse(&s, str.ptr, str.byte_len, &read); if(status != UPB_STATUS_OK && read != str.byte_len) { - fprintf(stderr, "Error. :( error=%d, read=%d\n", status, read); + fprintf(stderr, "Error. :( error=%d, read=%lu\n", status, read); return 1; } total += str.byte_len; } - fprintf(stderr, "Parsed %sB\n", eng(total, 3, false)); + double elapsed = ((double)clock() - before) / CLOCKS_PER_SEC; + fprintf(stderr, "Parsed %sB, ", eng(total, 3, false)); + fprintf(stderr, "%sB/s\n", eng(total/elapsed, 3, false)); upb_msg_parse_free(&s); upb_msgdata_free(data, m, true); upb_context_free(&c); upb_strfree(str); + + //benchmarks::SpeedMessage2 msg; + //std::string stlstr(str.ptr, str.byte_len); + //before = clock(); + //for(int i = 0; i < 2000; i++) { + // msg.ParseFromString(stlstr); + // total += str.byte_len; + //} + //elapsed = ((double)clock() - before) / CLOCKS_PER_SEC; + //fprintf(stderr, "Parsed %sB, ", eng(total, 3, false)); + //fprintf(stderr, "%sB/s\n", eng(total/elapsed, 3, false)); }