summaryrefslogtreecommitdiff
path: root/benchmarks/parsetostruct.proto2_table.cc
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-08-04 19:46:42 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-08-04 19:46:42 -0700
commit84cd1538ee20b934c6892f38578a08106a934fe8 (patch)
treeecfc5baa4d47a276bf1509243778ae7940e08e83 /benchmarks/parsetostruct.proto2_table.cc
parent2aaea5390a841e2682a318746e90aebbe8a955b9 (diff)
Integrated benchmarks into main Makefile.
Diffstat (limited to 'benchmarks/parsetostruct.proto2_table.cc')
-rw-r--r--benchmarks/parsetostruct.proto2_table.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/benchmarks/parsetostruct.proto2_table.cc b/benchmarks/parsetostruct.proto2_table.cc
new file mode 100644
index 0000000..815834e
--- /dev/null
+++ b/benchmarks/parsetostruct.proto2_table.cc
@@ -0,0 +1,44 @@
+
+#include "main.c"
+#include <google/protobuf/dynamic_message.h>
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include MESSAGE_HFILE
+
+static std::string str;
+static google::protobuf::DynamicMessageFactory factory;
+static google::protobuf::Message *msg;
+
+static bool initialize()
+{
+ /* Read the message data itself. */
+ std::ifstream stream(MESSAGE_FILE);
+ if(!stream.is_open()) {
+ fprintf(stderr, "Error opening " MESSAGE_FILE ".\n");
+ return false;
+ }
+ std::stringstream stringstream;
+ stringstream << stream.rdbuf();
+ str = stringstream.str();
+
+ /* Create the DynamicMessage. */
+ const google::protobuf::Message *dynamic_msg_prototype =
+ factory.GetPrototype(MESSAGE_CIDENT::descriptor());
+ msg = dynamic_msg_prototype->New();
+ return true;
+}
+
+static void cleanup()
+{
+ delete msg;
+}
+
+static size_t run()
+{
+ if(!msg->ParseFromString(str)) {
+ fprintf(stderr, "Error parsing with proto2.\n");
+ return 0;
+ }
+ return str.size();
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback