diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-07-10 15:59:42 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-07-10 15:59:42 -0700 |
commit | 528cdd2ecd8f1b43ac8b7bad3f188c717507c718 (patch) | |
tree | 67776d4a216a5d0ec16fdf4997d2b002a7794576 /benchmark | |
parent | 2abf3428043fdbefdcc611baae5c86a58aacd3a3 (diff) |
Updated benchmark to correctly test both upb and proto2.
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/benchmark.cc | 28 |
1 files changed, 16 insertions, 12 deletions
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)); } |