From 528cdd2ecd8f1b43ac8b7bad3f188c717507c718 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 10 Jul 2009 15:59:42 -0700 Subject: Updated benchmark to correctly test both upb and proto2. --- benchmark/benchmark.cc | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'benchmark') diff --git a/benchmark/benchmark.cc b/benchmark/benchmark.cc index a91c716..efdac24 100644 --- a/benchmark/benchmark.cc +++ b/benchmark/benchmark.cc @@ -52,21 +52,25 @@ int main () total += str.byte_len; } double elapsed = ((double)clock() - before) / CLOCKS_PER_SEC; - fprintf(stderr, "Parsed %sB, ", eng(total, 3, false)); + fprintf(stderr, "upb 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)); + benchmarks::SpeedMessage2 msg; + std::string stlstr(str.ptr, str.byte_len); + upb_strfree(str); + total = 0; + before = clock(); + for(int i = 0; i < 2000; i++) { + if(!msg.ParseFromString(stlstr)) { + fprintf(stderr, "Error parsing with proto2.\n"); + return 1; + } + total += str.byte_len; + } + elapsed = ((double)clock() - before) / CLOCKS_PER_SEC; + fprintf(stderr, "proto2 parsed %sB, ", eng(total, 3, false)); + fprintf(stderr, "%sB/s\n", eng(total/elapsed, 3, false)); } -- cgit v1.2.3