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