summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2011-07-14 23:15:00 -0700
committerJoshua Haberman <jhaberman@gmail.com>2011-07-14 23:15:00 -0700
commit6a1f3a66939308668ab8dce0d195afec16e02af9 (patch)
tree8d1236c0d7269caa1ece95bfe584afe9b550c006 /benchmarks
parent559e23c796f973a65d05c76e211835b126ee8ac8 (diff)
Major refactoring: upb_string is gone in favor of upb_strref.
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/parsestream.upb_table.c35
-rw-r--r--benchmarks/parsetostruct.upb_table.c44
2 files changed, 25 insertions, 54 deletions
diff --git a/benchmarks/parsestream.upb_table.c b/benchmarks/parsestream.upb_table.c
index b1763da..a321010 100644
--- a/benchmarks/parsestream.upb_table.c
+++ b/benchmarks/parsestream.upb_table.c
@@ -1,12 +1,14 @@
#include "main.c"
+#include <stdlib.h>
#include "upb_def.h"
#include "upb_decoder.h"
#include "upb_strstream.h"
#include "upb_glue.h"
-static upb_string *input_str;
+static char *input_str;
+static size_t input_len;
static upb_msgdef *def;
static upb_decoder decoder;
static upb_stringsrc stringsrc;
@@ -29,32 +31,21 @@ static bool initialize()
// Initialize upb state, decode descriptor.
upb_status status = UPB_STATUS_INIT;
upb_symtab *s = upb_symtab_new();
-
- upb_string *fds_str = upb_strreadfile(MESSAGE_DESCRIPTOR_FILE);
- if(fds_str == NULL) {
- fprintf(stderr, "Couldn't read " MESSAGE_DESCRIPTOR_FILE ":"),
- upb_printerr(&status);
- return false;
- }
- upb_read_descriptor(s, fds_str, &status);
- upb_string_unref(fds_str);
-
+ upb_read_descriptorfile(s, MESSAGE_DESCRIPTOR_FILE, &status);
if(!upb_ok(&status)) {
- fprintf(stderr, "Error importing " MESSAGE_DESCRIPTOR_FILE ":");
- upb_printerr(&status);
+ upb_status_print(&status, stderr);
return false;
}
- def = upb_dyncast_msgdef(upb_symtab_lookup(s, UPB_STRLIT(MESSAGE_NAME)));
+ def = upb_dyncast_msgdef(upb_symtab_lookup(s, MESSAGE_NAME));
if(!def) {
- fprintf(stderr, "Error finding symbol '" UPB_STRFMT "'.\n",
- UPB_STRARG(UPB_STRLIT(MESSAGE_NAME)));
+ fprintf(stderr, "Error finding symbol '%s'.\n", MESSAGE_NAME);
return false;
}
upb_symtab_unref(s);
// Read the message data itself.
- input_str = upb_strreadfile(MESSAGE_FILE);
+ input_str = upb_readfile(MESSAGE_FILE, &input_len);
if(input_str == NULL) {
fprintf(stderr, "Error reading " MESSAGE_FILE "\n");
return false;
@@ -72,7 +63,7 @@ static bool initialize()
static void cleanup()
{
- upb_string_unref(input_str);
+ free(input_str);
upb_def_unref(UPB_UPCAST(def));
upb_decoder_uninit(&decoder);
upb_stringsrc_uninit(&stringsrc);
@@ -82,14 +73,14 @@ static size_t run(int i)
{
(void)i;
upb_status status = UPB_STATUS_INIT;
- upb_stringsrc_reset(&stringsrc, input_str);
- upb_decoder_reset(&decoder, upb_stringsrc_bytesrc(&stringsrc), NULL);
+ upb_stringsrc_reset(&stringsrc, input_str, input_len);
+ upb_decoder_reset(&decoder, upb_stringsrc_bytesrc(&stringsrc), 0, UINT64_MAX, NULL);
upb_decoder_decode(&decoder, &status);
if(!upb_ok(&status)) goto err;
- return upb_string_len(input_str);
+ return input_len;
err:
fprintf(stderr, "Decode error: ");
- upb_printerr(&status);
+ upb_status_print(&status, stderr);
return 0;
}
diff --git a/benchmarks/parsetostruct.upb_table.c b/benchmarks/parsetostruct.upb_table.c
index f0ddb99..76cbf21 100644
--- a/benchmarks/parsetostruct.upb_table.c
+++ b/benchmarks/parsetostruct.upb_table.c
@@ -7,8 +7,8 @@
#include "upb_glue.h"
#include "upb_msg.h"
-static upb_string *input_str;
static upb_msgdef *def;
+static size_t len;
static void *msg;
static upb_stringsrc strsrc;
static upb_decoder d;
@@ -18,33 +18,22 @@ static bool initialize()
// Initialize upb state, decode descriptor.
upb_status status = UPB_STATUS_INIT;
upb_symtab *s = upb_symtab_new();
-
- upb_string *fds_str = upb_strreadfile(MESSAGE_DESCRIPTOR_FILE);
- if(fds_str == NULL) {
- fprintf(stderr, "Couldn't read " MESSAGE_DESCRIPTOR_FILE ":"),
- upb_printerr(&status);
- return false;
- }
- upb_read_descriptor(s, fds_str, &status);
- upb_string_unref(fds_str);
-
+ upb_read_descriptorfile(s, MESSAGE_DESCRIPTOR_FILE, &status);
if(!upb_ok(&status)) {
- fprintf(stderr, "Error importing " MESSAGE_DESCRIPTOR_FILE ":");
- upb_printerr(&status);
+ upb_status_print(&status, stderr);
return false;
}
- def = upb_dyncast_msgdef(upb_symtab_lookup(s, UPB_STRLIT(MESSAGE_NAME)));
+ def = upb_dyncast_msgdef(upb_symtab_lookup(s, MESSAGE_NAME));
if(!def) {
- fprintf(stderr, "Error finding symbol '" UPB_STRFMT "'.\n",
- UPB_STRARG(UPB_STRLIT(MESSAGE_NAME)));
+ fprintf(stderr, "Error finding symbol '%s'.\n", MESSAGE_NAME);
return false;
}
upb_symtab_unref(s);
// Read the message data itself.
- input_str = upb_strreadfile(MESSAGE_FILE);
- if(input_str == NULL) {
+ char *str = upb_readfile(MESSAGE_FILE, &len);
+ if(str == NULL) {
fprintf(stderr, "Error reading " MESSAGE_FILE "\n");
return false;
}
@@ -52,25 +41,17 @@ static bool initialize()
msg = upb_stdmsg_new(def);
upb_stringsrc_init(&strsrc);
+ upb_stringsrc_reset(&strsrc, str, len);
upb_decoder_initformsgdef(&d, def);
if (!BYREF) {
- // Pretend the input string is stack-allocated, which will force its data
- // to be copied instead of referenced. There is no good reason to do this,
- // except to benchmark against proto2 more fairly, which in its open-source
- // release does not support referencing the input string.
- input_str->refcount.v = _UPB_STRING_REFCOUNT_STACK;
+ // TODO: use byref/byval accessors.
}
return true;
}
static void cleanup()
{
- if (!BYREF) {
- // Undo our fabrication from before.
- input_str->refcount.v = 1;
- }
- upb_string_unref(input_str);
upb_stdmsg_free(msg, def);
upb_def_unref(UPB_UPCAST(def));
upb_stringsrc_uninit(&strsrc);
@@ -82,14 +63,13 @@ static size_t run(int i)
(void)i;
upb_status status = UPB_STATUS_INIT;
upb_msg_clear(msg, def);
- upb_stringsrc_reset(&strsrc, input_str);
- upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), msg);
+ upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), 0, UINT64_MAX, msg);
upb_decoder_decode(&d, &status);
if(!upb_ok(&status)) goto err;
- return upb_string_len(input_str);
+ return len;
err:
fprintf(stderr, "Decode error: ");
- upb_printerr(&status);
+ upb_status_print(&status, stderr);
return 0;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback