| 33 | typedef bool (*Decompress)(const butil::IOBuf&, google::protobuf::Message*); |
| 34 | |
| 35 | inline void CompressMessage(const char* method_name, |
| 36 | int num, snappy_message::SnappyMessageProto& msg, |
| 37 | int len, Compress compress, Decompress decompress) { |
| 38 | butil::Timer timer; |
| 39 | size_t compression_length = 0; |
| 40 | int64_t total_compress_time = 0; |
| 41 | int64_t total_decompress_time = 0; |
| 42 | snappy_message::SnappyMessageProto new_msg; |
| 43 | for (int index = 0; index < num; index++) { |
| 44 | butil::IOBuf buf; |
| 45 | timer.start(); |
| 46 | ASSERT_TRUE(compress(msg, &buf)); |
| 47 | timer.stop(); |
| 48 | total_compress_time += timer.n_elapsed(); |
| 49 | compression_length += buf.length(); |
| 50 | timer.start(); |
| 51 | ASSERT_TRUE(decompress(buf, &new_msg)); |
| 52 | timer.stop(); |
| 53 | total_decompress_time += timer.n_elapsed(); |
| 54 | } |
| 55 | float compression_ratio = compression_length / (((double)num) * len); |
| 56 | printf("%20s%20d%20f%20f%30f%30f%29f%%\n", method_name, len, |
| 57 | total_compress_time/1000.0/num, total_decompress_time/1000.0/num, |
| 58 | 1000000000.0/1024/1024*num*len/total_compress_time, |
| 59 | 1000000000.0/1024/1024*num*len/total_decompress_time, |
| 60 | compression_ratio*100.0); |
| 61 | } |
| 62 | |
| 63 | static bool SnappyDecompressIOBuf(char* input, size_t len, butil::IOBuf* buf) { |
| 64 | size_t decompress_length; |