4 #include <gtest/gtest.h>
32 void TestCompression(
int num,
int min_len,
int max_len, THdfsCompression::type codec) {
33 vector<string> strings;
34 uint8_t* buffer = (uint8_t*)malloc(max_len * num);
36 int len_delta = max_len - min_len;
37 len_delta = max(len_delta, 1);
38 for (
int i = 0; i < num; ++i) {
39 int len = rand() % len_delta + min_len;
41 for (
int j = 0; j < len; ++j) {
42 buffer[offset++] = rand() % 26 +
'a';
44 strings.push_back(
string((
char*)buffer + start, len));
48 uint8_t* sorted_buffer = (uint8_t*)malloc(offset);
49 int sorted_offset = 0;
50 sort(strings.begin(), strings.end());
51 for (
int i = 0; i < strings.size(); ++i) {
52 memcpy(sorted_buffer + sorted_offset, strings[i].data(), strings[i].size());
53 sorted_offset += strings[i].size();
56 scoped_ptr<Codec> compressor;
59 int64_t compressed_len = compressor->MaxOutputLen(offset);
60 uint8_t* compressed_buffer = (uint8_t*)malloc(compressed_len);
61 compressor->ProcessBlock(
true, offset, buffer, &compressed_len, &compressed_buffer);
63 int64_t sorted_compressed_len = compressor->MaxOutputLen(offset);
64 uint8_t* sorted_compressed_buffer = (uint8_t*)malloc(sorted_compressed_len);
65 compressor->ProcessBlock(
true, offset, sorted_buffer, &sorted_compressed_len,
66 &sorted_compressed_buffer);
68 cout <<
"NumStrings=" << num <<
" MinLen=" << min_len <<
" MaxLen=" << max_len
69 <<
" Codec=" << codec << endl;
70 cout <<
" Uncompressed len: " << offset << endl;
71 cout <<
" Compressed len: " << compressed_len << endl;
72 cout <<
" Sorted Compressed len: " << sorted_compressed_len << endl;
76 free(compressed_buffer);
78 free(sorted_compressed_buffer);
83 int main(
int argc,
char **argv) {
static Status CreateCompressor(MemPool *mem_pool, bool reuse, THdfsCompression::type format, boost::scoped_ptr< Codec > *compressor)
int main(int argc, char **argv)
uint8_t offset[7 *64-sizeof(uint64_t)]
void TestCompression(int num, int min_len, int max_len, THdfsCompression::type codec)