| 1 | #include <string> |
| 2 | |
| 3 | #include <iostream> |
| 4 | #include <iomanip> |
| 5 | |
| 6 | #include <Core/Types.h> |
| 7 | #include <Common/Stopwatch.h> |
| 8 | #include <IO/WriteBufferFromFile.h> |
| 9 | #include <IO/ReadBufferFromFile.h> |
| 10 | #include <IO/ZlibDeflatingWriteBuffer.h> |
| 11 | #include <IO/ZlibInflatingReadBuffer.h> |
| 12 | #include <IO/WriteHelpers.h> |
| 13 | #include <IO/ReadHelpers.h> |
| 14 | |
| 15 | |
| 16 | int main(int, char **) |
| 17 | try |
| 18 | { |
| 19 | std::cout << std::fixed << std::setprecision(2); |
| 20 | |
| 21 | size_t n = 100000000; |
| 22 | Stopwatch stopwatch; |
| 23 | |
| 24 | { |
| 25 | auto buf = std::make_unique<DB::WriteBufferFromFile>("test_zlib_buffers.gz" , DBMS_DEFAULT_BUFFER_SIZE, O_WRONLY | O_CREAT | O_TRUNC); |
| 26 | DB::ZlibDeflatingWriteBuffer deflating_buf(std::move(buf), DB::CompressionMethod::Gzip, /* compression_level = */ 3); |
| 27 | |
| 28 | stopwatch.restart(); |
| 29 | for (size_t i = 0; i < n; ++i) |
| 30 | { |
| 31 | DB::writeIntText(i, deflating_buf); |
| 32 | DB::writeChar('\t', deflating_buf); |
| 33 | } |
| 34 | deflating_buf.finish(); |
| 35 | |
| 36 | stopwatch.stop(); |
| 37 | std::cout << "Writing done. Elapsed: " << stopwatch.elapsedSeconds() << " s." |
| 38 | << ", " << (deflating_buf.count() / stopwatch.elapsedSeconds() / 1000000) << " MB/s" |
| 39 | << std::endl; |
| 40 | } |
| 41 | |
| 42 | { |
| 43 | auto buf = std::make_unique<DB::ReadBufferFromFile>("test_zlib_buffers.gz" ); |
| 44 | DB::ZlibInflatingReadBuffer inflating_buf(std::move(buf), DB::CompressionMethod::Gzip); |
| 45 | |
| 46 | stopwatch.restart(); |
| 47 | for (size_t i = 0; i < n; ++i) |
| 48 | { |
| 49 | size_t x; |
| 50 | DB::readIntText(x, inflating_buf); |
| 51 | inflating_buf.ignore(); |
| 52 | |
| 53 | if (x != i) |
| 54 | throw DB::Exception("Failed!, read: " + std::to_string(x) + ", expected: " + std::to_string(i), 0); |
| 55 | } |
| 56 | stopwatch.stop(); |
| 57 | std::cout << "Reading done. Elapsed: " << stopwatch.elapsedSeconds() << " s." |
| 58 | << ", " << (inflating_buf.count() / stopwatch.elapsedSeconds() / 1000000) << " MB/s" |
| 59 | << std::endl; |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | catch (const DB::Exception & e) |
| 65 | { |
| 66 | std::cerr << e.what() << ", " << e.displayText() << std::endl; |
| 67 | return 1; |
| 68 | } |
| 69 | |