Added the beginnings of a benchmark.

pull/13171/head
Joshua Haberman 16 years ago
parent 34fe50818d
commit 137991c7b2
  1. 3
      Makefile
  2. 49
      benchmark.c
  3. BIN
      google_message1.dat
  4. BIN
      google_message2.dat
  5. 130
      google_messages.proto.bin

@ -3,7 +3,7 @@
CC=gcc CC=gcc
CXX=g++ CXX=g++
CFLAGS=-std=c99 CFLAGS=-std=c99
CPPFLAGS=-Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK -fomit-frame-pointer CPPFLAGS=-O0 -Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK
OBJ=upb_parse.o upb_table.o upb_msg.o upb_enum.o upb_context.o upb_string.o descriptor.o OBJ=upb_parse.o upb_table.o upb_msg.o upb_enum.o upb_context.o upb_string.o descriptor.o
all: $(OBJ) test_table tests upbc all: $(OBJ) test_table tests upbc
clean: clean:
@ -13,6 +13,7 @@ libupb.a: $(OBJ)
ar rcs libupb.a $(OBJ) ar rcs libupb.a $(OBJ)
test_table: libupb.a test_table: libupb.a
upbc: libupb.a upbc: libupb.a
benchmark: libupb.a
-include deps -include deps
deps: *.c *.h deps: *.c *.h

@ -0,0 +1,49 @@
#include "upb_context.h"
#include "upb_msg.h"
int main ()
{
struct upb_context c;
upb_context_init(&c);
struct upb_string fds;
if(!upb_strreadfile("google_speed.proto.bin", &fds)) {
fprintf(stderr, "Couldn't read google_speed.proto.bin.\n");
return 1;
}
if(!upb_context_parsefds(&c, &fds)) {
fprintf(stderr, "Error parsing or resolving proto.\n");
return 1;
}
upb_strfree(fds);
struct upb_string proto_name = UPB_STRLIT("benchmarks.SpeedMessage2");
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",
UPB_STRARG(proto_name));
return 1;
}
struct upb_msg *m = e->ref.msg;
struct upb_msg_parse_state s;
void *data = upb_msgdata_new(m);
upb_msg_parse_init(&s, data, m, false, true);
size_t read;
struct upb_string str;
if(!upb_strreadfile("google_message2.dat", &str)) {
fprintf(stderr, "Error reading google_message2.dat\n");
return 1;
}
upb_status_t status = upb_msg_parse(&s, str.ptr, str.byte_len, &read);
upb_msg_parse_free(&s);
upb_msgdata_free(data, m, true);
upb_context_free(&c);
upb_strfree(str);
if(status == UPB_STATUS_OK && read == str.byte_len) {
fprintf(stderr, "Success!\n");
return 0;
} else {
fprintf(stderr, "Error. :( error=%d, read=%d\n", status, read);
return 1;
}
}

Binary file not shown.

Binary file not shown.

@ -0,0 +1,130 @@
ï
google_speed.proto
benchmarks"ø
SpeedMessage1
field1 ( 
field9 ( 
field18 ( 
field80P (:false
field81Q (:true
field2 (
field3 (
field280˜ (
field6 (:0
field22 (
field4 ( 
field5 (
field59; (:false
field7 ( 
field16 (
field130 (:0
field12 (:true
field17 (:true
field13 (:true
field14 (:true
field104h (:0
field100d (:0
field101e (:0
field102f ( 
field103g ( 
field29 (:0
field30 (:false
field60< (:-1
field271<EFBFBD> (:-1
field272<EFBFBD> (:-1
field150 (
field23 (:0
field24 (:false
field25 (:04
field15 ( 2#.benchmarks.SpeedMessage1SubMessage
field78N (
field67C (:0
field68D (
field128 (:0(
field129<EFBFBD> ( :xxxxxxxxxxxxxxxxxxxxx
field131ƒ (:0"¢
SpeedMessage1SubMessage
field1 (:0
field2 (:0
field3 (:0
field15 ( 
field12 (:true
field13 (
field14 (
field16 (
field19 (:2
field20 (:true
field28 (:true
field21 (
field22 (
field23 (:false
field206Î (:false
field203Ë (
field204Ì (
field205Í ( 
field207Ï (
field300¬ (
SpeedMessage2
field1 ( 
field3 (
field4 (
field30 (
field75K (:false
field6 ( 
field2 ( 
field21 (:0
field71G (
field25 (
field109m (:0
field210Ò (:0
field211Ó (:0
field212Ô (:0
field213Õ (:0
field216Ø (:0
field217Ù (:0
field218Ú (:0
field220Ü (:0
field221Ý (:0
field222Þ (:0
field63? (0
group1
(
2 .benchmarks.SpeedMessage2.Group1
field128 ( 
field131ƒ (
field127 ( 
field129<EFBFBD> (
field130 (
field205Í (:false
field206Î (:falseÃ
Group1
field11 (
field26 (
field12 ( 
field13 ( 
field14 ( 
field15 (
field5 (
field27 ( 
field28 (
field29 ( 
field16 ( 
field22 ( 
field73I (
field20 (:0
field24 ( 8
field31 ( 2'.benchmarks.SpeedMessage2GroupedMessage"ß
SpeedMessage2GroupedMessage
field1 (
field2 (
field3 (:0
field4 (
field5 (
field6 (:true
field7 (:false
field8 (
field9 (
field10
(
field11 (
Loading…
Cancel
Save