summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-07 23:48:37 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-07 23:48:37 -0700
commit797bd11247fb0d5774b3fd6d9d562eaa5f8b14ae (patch)
tree6e43d51acc774c367288823936a439225cc03aad
parentb2bbafb67457835c4cf9061610ea9549740669c2 (diff)
Made benchmark test proto2 also.
-rw-r--r--benchmark.cc (renamed from benchmark.c)27
1 files changed, 23 insertions, 4 deletions
diff --git a/benchmark.c b/benchmark.cc
index aede9d3..05184bc 100644
--- a/benchmark.c
+++ b/benchmark.cc
@@ -1,4 +1,6 @@
+#include <time.h>
+#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));
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback