summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-10 15:59:42 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-10 15:59:42 -0700
commit528cdd2ecd8f1b43ac8b7bad3f188c717507c718 (patch)
tree67776d4a216a5d0ec16fdf4997d2b002a7794576
parent2abf3428043fdbefdcc611baae5c86a58aacd3a3 (diff)
Updated benchmark to correctly test both upb and proto2.
-rw-r--r--Makefile2
-rw-r--r--benchmark/benchmark.cc28
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));
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback