From 462b26c1cc041a8fa26deb62cf12f1f351a5b2f6 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 8 Jul 2009 12:06:47 -0700 Subject: Directory restructuring. --- benchmark/benchmark.cc | 72 +++++++++++++++++++ benchmark/google_message1.dat | Bin 0 -> 228 bytes benchmark/google_message2.dat | Bin 0 -> 84570 bytes benchmark/google_messages.proto | 134 ++++++++++++++++++++++++++++++++++++ benchmark/google_messages.proto.bin | 130 ++++++++++++++++++++++++++++++++++ 5 files changed, 336 insertions(+) create mode 100644 benchmark/benchmark.cc create mode 100644 benchmark/google_message1.dat create mode 100644 benchmark/google_message2.dat create mode 100644 benchmark/google_messages.proto create mode 100644 benchmark/google_messages.proto.bin (limited to 'benchmark') diff --git a/benchmark/benchmark.cc b/benchmark/benchmark.cc new file mode 100644 index 0000000..05184bc --- /dev/null +++ b/benchmark/benchmark.cc @@ -0,0 +1,72 @@ + +#include +#include "google_speed.pb.h" +#include "test_util.h" +#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_messages.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); + 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", + 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; + } + size_t total = 0; + 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=%lu\n", status, read); + return 1; + } + total += str.byte_len; + } + 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)); +} diff --git a/benchmark/google_message1.dat b/benchmark/google_message1.dat new file mode 100644 index 0000000..bc0f064 Binary files /dev/null and b/benchmark/google_message1.dat differ diff --git a/benchmark/google_message2.dat b/benchmark/google_message2.dat new file mode 100644 index 0000000..06c0944 Binary files /dev/null and b/benchmark/google_message2.dat differ diff --git a/benchmark/google_messages.proto b/benchmark/google_messages.proto new file mode 100644 index 0000000..97356ec --- /dev/null +++ b/benchmark/google_messages.proto @@ -0,0 +1,134 @@ + +package benchmarks; + +message SpeedMessage1 { + required string field1 = 1; + optional string field9 = 9; + optional string field18 = 18; + optional bool field80 = 80 [default=false]; + optional bool field81 = 81 [default=true]; + required int32 field2 = 2; + required int32 field3 = 3; + optional int32 field280 = 280; + optional int32 field6 = 6 [default=0]; + optional int64 field22 = 22; + optional string field4 = 4; + repeated fixed64 field5 = 5; + optional bool field59 = 59 [default=false]; + optional string field7 = 7; + optional int32 field16 = 16; + optional int32 field130 = 130 [default=0]; + optional bool field12 = 12 [default=true]; + optional bool field17 = 17 [default=true]; + optional bool field13 = 13 [default=true]; + optional bool field14 = 14 [default=true]; + optional int32 field104 = 104 [default=0]; + optional int32 field100 = 100 [default=0]; + optional int32 field101 = 101 [default=0]; + optional string field102 = 102; + optional string field103 = 103; + optional int32 field29 = 29 [default=0]; + optional bool field30 = 30 [default=false]; + optional int32 field60 = 60 [default=-1]; + optional int32 field271 = 271 [default=-1]; + optional int32 field272 = 272 [default=-1]; + optional int32 field150 = 150; + optional int32 field23 = 23 [default=0]; + optional bool field24 = 24 [default=false]; + optional int32 field25 = 25 [default=0]; + optional SpeedMessage1SubMessage field15 = 15; + optional bool field78 = 78; + optional int32 field67 = 67 [default=0]; + optional int32 field68 = 68; + optional int32 field128 = 128 [default=0]; + optional string field129 = 129 [default="xxxxxxxxxxxxxxxxxxxxx"]; + optional int32 field131 = 131 [default=0]; +} + +message SpeedMessage1SubMessage { + optional int32 field1 = 1 [default=0]; + optional int32 field2 = 2 [default=0]; + optional int32 field3 = 3 [default=0]; + optional string field15 = 15; + optional bool field12 = 12 [default=true]; + optional int64 field13 = 13; + optional int64 field14 = 14; + optional int32 field16 = 16; + optional int32 field19 = 19 [default=2]; + optional bool field20 = 20 [default=true]; + optional bool field28 = 28 [default=true]; + optional fixed64 field21 = 21; + optional int32 field22 = 22; + optional bool field23 = 23 [ default=false ]; + optional bool field206 = 206 [default=false]; + optional fixed32 field203 = 203; + optional int32 field204 = 204; + optional string field205 = 205; + optional uint64 field207 = 207; + optional uint64 field300 = 300; +} + +message SpeedMessage2 { + optional string field1 = 1; + optional int64 field3 = 3; + optional int64 field4 = 4; + optional int64 field30 = 30; + optional bool field75 = 75 [default=false]; + optional string field6 = 6; + optional bytes field2 = 2; + optional int32 field21 = 21 [default=0]; + optional int32 field71 = 71; + optional float field25 = 25; + optional int32 field109 = 109 [default=0]; + optional int32 field210 = 210 [default=0]; + optional int32 field211 = 211 [default=0]; + optional int32 field212 = 212 [default=0]; + optional int32 field213 = 213 [default=0]; + optional int32 field216 = 216 [default=0]; + optional int32 field217 = 217 [default=0]; + optional int32 field218 = 218 [default=0]; + optional int32 field220 = 220 [default=0]; + optional int32 field221 = 221 [default=0]; + optional float field222 = 222 [default=0.0]; + optional int32 field63 = 63; + + repeated group Group1 = 10 { + required float field11 = 11; + optional float field26 = 26; + optional string field12 = 12; + optional string field13 = 13; + repeated string field14 = 14; + required uint64 field15 = 15; + optional int32 field5 = 5; + optional string field27 = 27; + optional int32 field28 = 28; + optional string field29 = 29; + optional string field16 = 16; + repeated string field22 = 22; + repeated int32 field73 = 73; + optional int32 field20 = 20 [default=0]; + optional string field24 = 24; + optional SpeedMessage2GroupedMessage field31 = 31; + } + repeated string field128 = 128; + optional int64 field131 = 131; + repeated string field127 = 127; + optional int32 field129 = 129; + repeated int64 field130 = 130; + optional bool field205 = 205 [default=false]; + optional bool field206 = 206 [default=false]; +} + +message SpeedMessage2GroupedMessage { + optional float field1 = 1; + optional float field2 = 2; + optional float field3 = 3 [default=0.0]; + optional bool field4 = 4; + optional bool field5 = 5; + optional bool field6 = 6 [default=true]; + optional bool field7 = 7 [default=false]; + optional float field8 = 8; + optional bool field9 = 9; + optional float field10 = 10; + optional int64 field11 = 11; +} diff --git a/benchmark/google_messages.proto.bin b/benchmark/google_messages.proto.bin new file mode 100644 index 0000000..0531d7e --- /dev/null +++ b/benchmark/google_messages.proto.bin @@ -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 (:-1 +field272 (:-1 +field150– ( +field23 (:0 +field24 (:false +field25 (:04 +field15 ( 2#.benchmarks.SpeedMessage1SubMessage +field78N ( +field67C (:0 +field68D ( +field128€ (:0( +field129 ( :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 ( +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 ( \ No newline at end of file -- cgit v1.2.3