[PATCH] D93761: [libObject/Decompressor] - Use `resize_for_overwrite` in Decompressor::resizeAndDecompress().
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 13 04:11:24 PST 2021
grimar added a comment.
Ok. I've used the following piece of code to construct a 1Gb of random compressed data and estimated
the difference between the old and the new code in Release.
auto T1 = std::chrono::high_resolution_clock::now();
constexpr uint64_t Size = 1024 * 1024 * 1024uLL;
std::vector<uint8_t> Data;
Data.reserve(Size);
for (size_t I = 0; I != Size; ++I)
Data.push_back(rand());
auto T2 = std::chrono::high_resolution_clock::now();
outs()
<< "Create data (microseconds): "
<< std::chrono::duration_cast<std::chrono::microseconds>(T2 - T1).count()
<< "\n";
SmallVector<char, 1> CompressedData;
T1 = std::chrono::high_resolution_clock::now();
if (Error Err = zlib::compress(
StringRef(reinterpret_cast<const char *>(Data.data()), Size),
CompressedData)) {
return 1;
}
T2 = std::chrono::high_resolution_clock::now();
outs()
<< "Compress data (microseconds): "
<< std::chrono::duration_cast<std::chrono::microseconds>(T2 - T1).count()
<< "\n";
outs() << "Compressed data size: " << CompressedData.size() << "\n";
object::Decompressor Decompressor(
StringRef(CompressedData.data(), CompressedData.size()));
Decompressor.DecompressedSize = Size;
T1 = std::chrono::high_resolution_clock::now();
SmallString<0> DecompressedData;
Decompressor.resizeAndDecompress(DecompressedData);
T2 = std::chrono::high_resolution_clock::now();
outs()
<< "Decompress data (microseconds): "
<< std::chrono::duration_cast<std::chrono::microseconds>(T2 - T1).count()
<< "\n";
Selected an average result from 3 runs:
----------------------------------------
With `resize`:
----------------------------------------
D:\XXX\LLVM\llvm-project\build\Release\bin>yaml2obj.exe
Create data (microseconds): 16963852
Compress data (microseconds): 27999644
Compressed data size: 1074069335
Decompress data (microseconds): 836237
----------------------------------------
With `resize_for_overwrite`:
----------------------------------------
D:\XXX\LLVM\llvm-project\build\Release\bin>yaml2obj.exe
Create data (microseconds): 17025348
Compress data (microseconds): 27997363
Compressed data size: 1074069335
Decompress data (microseconds): 549606
836237 * 0.657 == 549606, i.e. the new code is about 35% faster for me.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93761/new/
https://reviews.llvm.org/D93761
More information about the llvm-commits
mailing list