MCPcopy Create free account
hub / github.com/apache/brpc / CompressMessage

Function CompressMessage

test/brpc_snappy_compress_unittest.cpp:35–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33typedef bool (*Decompress)(const butil::IOBuf&, google::protobuf::Message*);
34
35inline 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
63static bool SnappyDecompressIOBuf(char* input, size_t len, butil::IOBuf* buf) {
64 size_t decompress_length;

Callers 1

TEST_FFunction · 0.85

Calls 4

n_elapsedMethod · 0.80
startMethod · 0.45
stopMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected