Re: [protobuf] Performance analysis of RepeatedField versus generated class
Option B avoids an extra copy of the data. It should work with all versions of protocol buffers. Use it if profiling shows a lot of time spent in this code, otherwise use whichever version you find easier to follow. On Tue, Aug 17, 2010 at 8:51 AM, nirajshr niraj...@gmail.com wrote: I want to know which of the following implementation is better in terms of performance and usability. Option A is much easier and portable across different protobuf versions. Is it worth the trouble trying to go with Option B? In my tests, I could not find much of a performance gain by using Option B. Option A uses the protobuf compiler generated class to loop through each elements of a repeated doubles. On the other hand, Option B uses RepeatedField class to extract a pointer to the array of doubles. Option A: int size = bucket.bucketdouble(j).data_size(); double* doubleVector = new double[size]; for(int k=0; ksize; k++) { doubleVector[k] = bucket.bucketdouble(j).data(k); } // Custom function that takes arrays of doubles add_double_vector(doubleVector, size); delete [] doubleVector; Option B: using namespace google::protobuf; DoubleData* doubledata_m = deal_pb.mutable_bucket(i)- mutable_bucketdouble(j); RepeatedField double * doublearray_m = doubledata_m-mutable_data(); // Custom function that takes arrays of doubles add_double_vector(doublearray_m-mutable_data(), doublearray_m- size()); My .proto file looks something like this: message DoubleData { required string name = 1 [default = noname]; repeated double data = 2; } message Bucket { repeated DoubleData bucketDouble = 2; } -- You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/protobuf?hl=en. -- You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
Re: [protobuf] Performance analysis of RepeatedField versus generated class
BTW On Tue, Aug 17, 2010 at 8:51 AM, nirajshr niraj...@gmail.com wrote: repeated DoubleData bucketDouble = 2; You should declare this field packed: repeated DoubleData bucketDouble = 2 [packed=true]; This will improve efficiency on the wire. -- You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
Re: [protobuf] Performance analysis of RepeatedField versus generated class
How about this way-more-readable variant of option B: add_double_vector(deal_pb.bucket(i).bucketdouble().data(), deal_pb.bucket(i).bucketdouble().size()); This assumes that add_bouble_vector only needs a const pointer. If it needs a non-const pointer, add the appropriate mutable_ prefixes. On Tue, Aug 17, 2010 at 8:51 AM, nirajshr niraj...@gmail.com wrote: I want to know which of the following implementation is better in terms of performance and usability. Option A is much easier and portable across different protobuf versions. Is it worth the trouble trying to go with Option B? In my tests, I could not find much of a performance gain by using Option B. Option A uses the protobuf compiler generated class to loop through each elements of a repeated doubles. On the other hand, Option B uses RepeatedField class to extract a pointer to the array of doubles. Option A: int size = bucket.bucketdouble(j).data_size(); double* doubleVector = new double[size]; for(int k=0; ksize; k++) { doubleVector[k] = bucket.bucketdouble(j).data(k); } // Custom function that takes arrays of doubles add_double_vector(doubleVector, size); delete [] doubleVector; Option B: using namespace google::protobuf; DoubleData* doubledata_m = deal_pb.mutable_bucket(i)- mutable_bucketdouble(j); RepeatedField double * doublearray_m = doubledata_m-mutable_data(); // Custom function that takes arrays of doubles add_double_vector(doublearray_m-mutable_data(), doublearray_m- size()); My .proto file looks something like this: message DoubleData { required string name = 1 [default = noname]; repeated double data = 2; } message Bucket { repeated DoubleData bucketDouble = 2; } -- You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/protobuf?hl=en. -- You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.