You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
clang format apply
This commit is contained in:
@ -23,104 +23,86 @@
|
||||
|
||||
class CompressionTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::string genPermutations(string& data)
|
||||
{
|
||||
std::string generated;
|
||||
generate(data, 0, generated);
|
||||
return generated;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string genPermutations(string& data)
|
||||
private:
|
||||
void generate(string& data, uint32_t i, std::string& generated)
|
||||
{
|
||||
if (i == data.size())
|
||||
{
|
||||
std::string generated;
|
||||
generate(data, 0, generated);
|
||||
return generated;
|
||||
generated.append(data);
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
void generate(string& data, uint32_t i, std::string& generated)
|
||||
for (uint32_t k = i, e = data.size(); k < e; ++k)
|
||||
{
|
||||
if (i == data.size())
|
||||
{
|
||||
generated.append(data);
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t k = i, e = data.size(); k < e; ++k)
|
||||
{
|
||||
std::swap(data[i], data[k]);
|
||||
generate(data, i + 1, generated);
|
||||
std::swap(data[i], data[k]);
|
||||
}
|
||||
std::swap(data[i], data[k]);
|
||||
generate(data, i + 1, generated);
|
||||
std::swap(data[i], data[k]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(CompressionTest, LZ4CanCompress)
|
||||
{
|
||||
std::string originalData =
|
||||
"This program is free software; you can redistribute it and/or"
|
||||
"modify it under the terms of the GNU General Public License"
|
||||
"as published by the Free Software Foundation; version 2 of"
|
||||
"the License.";
|
||||
std::string originalData =
|
||||
"This program is free software; you can redistribute it and/or"
|
||||
"modify it under the terms of the GNU General Public License"
|
||||
"as published by the Free Software Foundation; version 2 of"
|
||||
"the License.";
|
||||
|
||||
std::unique_ptr<compress::CompressInterface> compressor(
|
||||
new compress::CompressInterfaceLZ4());
|
||||
std::unique_ptr<compress::CompressInterface> compressor(new compress::CompressInterfaceLZ4());
|
||||
|
||||
size_t originalSize = originalData.size();
|
||||
size_t compressedSize = compressor->maxCompressedSize(originalSize);
|
||||
std::unique_ptr<char[]> compressedData(new char[compressedSize]);
|
||||
std::memset(compressedData.get(), 0, compressedSize);
|
||||
size_t originalSize = originalData.size();
|
||||
size_t compressedSize = compressor->maxCompressedSize(originalSize);
|
||||
std::unique_ptr<char[]> compressedData(new char[compressedSize]);
|
||||
std::memset(compressedData.get(), 0, compressedSize);
|
||||
|
||||
auto rc = compressor->compress(originalData.data(), originalSize,
|
||||
compressedData.get(), &compressedSize);
|
||||
ASSERT_EQ(rc, 0);
|
||||
auto rc = compressor->compress(originalData.data(), originalSize, compressedData.get(), &compressedSize);
|
||||
ASSERT_EQ(rc, 0);
|
||||
|
||||
std::unique_ptr<char[]> uncompressedData(new char[originalSize]);
|
||||
rc = compressor->uncompress(compressedData.get(), compressedSize,
|
||||
uncompressedData.get(), &originalSize);
|
||||
ASSERT_EQ(rc, 0);
|
||||
std::string result(uncompressedData.get());
|
||||
EXPECT_EQ(originalData, result);
|
||||
std::unique_ptr<char[]> uncompressedData(new char[originalSize]);
|
||||
rc = compressor->uncompress(compressedData.get(), compressedSize, uncompressedData.get(), &originalSize);
|
||||
ASSERT_EQ(rc, 0);
|
||||
std::string result(uncompressedData.get());
|
||||
EXPECT_EQ(originalData, result);
|
||||
}
|
||||
|
||||
TEST_F(CompressionTest, LZvsSnappyUnique)
|
||||
{
|
||||
std::unique_ptr<compress::CompressInterface> lz4Compressor(
|
||||
new compress::CompressInterfaceLZ4());
|
||||
std::unique_ptr<compress::CompressInterface> snappyCompressor(
|
||||
new compress::CompressInterfaceSnappy());
|
||||
// Generate permutations.
|
||||
// 9! * 9 == 3265920 (closer to current chunk size)
|
||||
std::vector<std::string> dataPool{"abcdefghi", "aaadefghi", "aaaaafghi",
|
||||
"aaaaaaahi", "aaaaaaaaj"};
|
||||
std::unique_ptr<compress::CompressInterface> lz4Compressor(new compress::CompressInterfaceLZ4());
|
||||
std::unique_ptr<compress::CompressInterface> snappyCompressor(new compress::CompressInterfaceSnappy());
|
||||
// Generate permutations.
|
||||
// 9! * 9 == 3265920 (closer to current chunk size)
|
||||
std::vector<std::string> dataPool{"abcdefghi", "aaadefghi", "aaaaafghi", "aaaaaaahi", "aaaaaaaaj"};
|
||||
|
||||
for (auto& data : dataPool)
|
||||
{
|
||||
std::cout << "Permutations generated for: " << data << std::endl;
|
||||
auto generated = genPermutations(data);
|
||||
auto generatedSize = generated.size();
|
||||
for (auto& data : dataPool)
|
||||
{
|
||||
std::cout << "Permutations generated for: " << data << std::endl;
|
||||
auto generated = genPermutations(data);
|
||||
auto generatedSize = generated.size();
|
||||
|
||||
auto compressedSizeLZ4 =
|
||||
lz4Compressor->maxCompressedSize(generatedSize);
|
||||
auto compressedSizeSnappy =
|
||||
snappyCompressor->maxCompressedSize(generatedSize);
|
||||
auto compressedSizeLZ4 = lz4Compressor->maxCompressedSize(generatedSize);
|
||||
auto compressedSizeSnappy = snappyCompressor->maxCompressedSize(generatedSize);
|
||||
|
||||
std::unique_ptr<char[]> lz4CompressedData(new char[compressedSizeLZ4]);
|
||||
auto rc = lz4Compressor->compress(generated.data(), generatedSize,
|
||||
lz4CompressedData.get(),
|
||||
&compressedSizeLZ4);
|
||||
ASSERT_EQ(rc, 0);
|
||||
std::unique_ptr<char[]> lz4CompressedData(new char[compressedSizeLZ4]);
|
||||
auto rc =
|
||||
lz4Compressor->compress(generated.data(), generatedSize, lz4CompressedData.get(), &compressedSizeLZ4);
|
||||
ASSERT_EQ(rc, 0);
|
||||
|
||||
std::unique_ptr<char[]> snappyCompressedData(
|
||||
new char[compressedSizeSnappy]);
|
||||
rc = snappyCompressor->compress(generated.data(), generatedSize,
|
||||
snappyCompressedData.get(),
|
||||
&compressedSizeSnappy);
|
||||
ASSERT_EQ(rc, 0);
|
||||
std::unique_ptr<char[]> snappyCompressedData(new char[compressedSizeSnappy]);
|
||||
rc = snappyCompressor->compress(generated.data(), generatedSize, snappyCompressedData.get(),
|
||||
&compressedSizeSnappy);
|
||||
ASSERT_EQ(rc, 0);
|
||||
|
||||
std::cout << "LZ ratio: "
|
||||
<< (float) ((float) generatedSize /
|
||||
(float) compressedSizeLZ4)
|
||||
<< std::endl;
|
||||
std::cout << "LZ ratio: " << (float)((float)generatedSize / (float)compressedSizeLZ4) << std::endl;
|
||||
|
||||
std::cout << "Snappy ratio: "
|
||||
<< (float) ((float) generatedSize /
|
||||
(float) compressedSizeSnappy)
|
||||
<< std::endl;
|
||||
}
|
||||
std::cout << "Snappy ratio: " << (float)((float)generatedSize / (float)compressedSizeSnappy) << std::endl;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user