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. --- Makefile | 2 +- benchmark/benchmark.cc | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index f04fd4a..2cffa4f 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ src/libupb.a: $(OBJ) ar rcs src/libupb.a $(OBJ) tests/test_table: src/libupb.a tools/upbc: src/libupb.a -benchmark/benchmark: src/libupb.a benchmark/google_messages.pb.h benchmark/google_messages.pb.o +benchmark/benchmark: src/libupb.a benchmark/google_messages.pb.h benchmark/google_messages.pb.o benchmark/benchmark.o $(CXX) $(CPPFLAGS) -o benchmark/benchmark benchmark/google_messages.pb.o benchmark/benchmark.cc src/libupb.a -lm -lprotobuf -lpthread benchmark/google_messages.pb.h benchmark/google_messages.pb: benchmark/google_messages.proto protoc benchmark/google_messages.proto --cpp_out=. -obenchmark/google_messages.proto.pb 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