summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-08-04 22:06:02 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-08-04 22:06:02 -0700
commit306bc554c67c23ddd52e5ece0e3971214b2da4e7 (patch)
tree898406cd3264ee2d001d334cd2b81922cbd23330 /benchmarks
parent1733b582579927379bc04a5838add06b76ada427 (diff)
More work on benchmarks (performance tests).
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/main.c10
-rw-r--r--benchmarks/parsetostruct.proto2_compiled.cc6
-rw-r--r--benchmarks/parsetostruct.proto2_table.cc12
-rw-r--r--benchmarks/parsetostruct.upb_table.c14
4 files changed, 26 insertions, 16 deletions
diff --git a/benchmarks/main.c b/benchmarks/main.c
index f66b4d0..df8298f 100644
--- a/benchmarks/main.c
+++ b/benchmarks/main.c
@@ -5,9 +5,15 @@
#include <unistd.h>
#include <string.h>
+/* Cycle between a bunch of different messages, to avoid performance
+ * variations due to memory effects of a particular allocation pattern. */
+#ifndef NUM_MESSAGES
+#define NUM_MESSAGES 32
+#endif
+
static bool initialize();
static void cleanup();
-static size_t run();
+static size_t run(int i);
int main (int argc, char *argv[])
{
@@ -32,7 +38,7 @@ int main (int argc, char *argv[])
clock_t before = clock();
for(int i = 0; true; i++) {
if((i & 0xFF) == 0 && (clock() - before > CLOCKS_PER_SEC)) break;
- size_t bytes = run();
+ size_t bytes = run(i);
if(bytes == 0) {
fprintf(stderr, "%s: failed.\n", argv[0]);
return 2;
diff --git a/benchmarks/parsetostruct.proto2_compiled.cc b/benchmarks/parsetostruct.proto2_compiled.cc
index 339e184..4091ed0 100644
--- a/benchmarks/parsetostruct.proto2_compiled.cc
+++ b/benchmarks/parsetostruct.proto2_compiled.cc
@@ -7,7 +7,7 @@
#include <fstream>
static std::string str;
-MESSAGE_CIDENT msg;
+MESSAGE_CIDENT msg[NUM_MESSAGES];
static bool initialize()
{
@@ -27,9 +27,9 @@ static void cleanup()
{
}
-static size_t run()
+static size_t run(int i)
{
- if(!msg.ParseFromString(str)) {
+ if(!msg[i%NUM_MESSAGES].ParseFromString(str)) {
fprintf(stderr, "Error parsing with proto2.\n");
return 0;
}
diff --git a/benchmarks/parsetostruct.proto2_table.cc b/benchmarks/parsetostruct.proto2_table.cc
index 815834e..ded267d 100644
--- a/benchmarks/parsetostruct.proto2_table.cc
+++ b/benchmarks/parsetostruct.proto2_table.cc
@@ -8,7 +8,7 @@
static std::string str;
static google::protobuf::DynamicMessageFactory factory;
-static google::protobuf::Message *msg;
+static google::protobuf::Message *msg[NUM_MESSAGES];
static bool initialize()
{
@@ -25,18 +25,20 @@ static bool initialize()
/* Create the DynamicMessage. */
const google::protobuf::Message *dynamic_msg_prototype =
factory.GetPrototype(MESSAGE_CIDENT::descriptor());
- msg = dynamic_msg_prototype->New();
+ for(int i = 0; i < NUM_MESSAGES; i++)
+ msg[i] = dynamic_msg_prototype->New();
return true;
}
static void cleanup()
{
- delete msg;
+ for(int i = 0; i < NUM_MESSAGES; i++)
+ delete msg[i];
}
-static size_t run()
+static size_t run(int i)
{
- if(!msg->ParseFromString(str)) {
+ if(!msg[i%NUM_MESSAGES]->ParseFromString(str)) {
fprintf(stderr, "Error parsing with proto2.\n");
return 0;
}
diff --git a/benchmarks/parsetostruct.upb_table.c b/benchmarks/parsetostruct.upb_table.c
index f93a6a7..751c982 100644
--- a/benchmarks/parsetostruct.upb_table.c
+++ b/benchmarks/parsetostruct.upb_table.c
@@ -8,7 +8,7 @@ static struct upb_context c;
static struct upb_string str;
static struct upb_msg_parse_state s;
static struct upb_msg *m;
-static void *data;
+static void *data[NUM_MESSAGES];
static bool initialize()
{
@@ -37,8 +37,8 @@ static bool initialize()
}
m = e->ref.msg;
- data = upb_msgdata_new(m);
- upb_msg_parse_init(&s, data, m, false, true);
+ for(int i = 0; i < 32; i++)
+ data[i] = upb_msgdata_new(m);
/* Read the message data itself. */
if(!upb_strreadfile(MESSAGE_FILE, &str)) {
@@ -50,17 +50,19 @@ static bool initialize()
static void cleanup()
{
+ for(int i = 0; i < 32; i++)
+ upb_msgdata_free(data[i], m, true);
upb_strfree(str);
upb_context_free(&c);
}
-static size_t run()
+static size_t run(int i)
{
size_t read;
- upb_msg_parse_reset(&s, data, m, false, BYREF);
+ upb_msg_parse_reset(&s, data[i%NUM_MESSAGES], m, false, BYREF);
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=%lu\n", status, read);
+ fprintf(stderr, "Error. :( error=%d, read=%zu\n", status, read);
return 0;
}
return read;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback