1 | #include <IO/WriteBufferValidUTF8.h> |
---|---|
2 | #include <IO/WriteBufferFromString.h> |
3 | #include <Common/Stopwatch.h> |
4 | #include <string> |
5 | #include <streambuf> |
6 | #include <iostream> |
7 | #include <cstdio> |
8 | |
9 | int main(int argc, char ** argv) |
10 | { |
11 | try |
12 | { |
13 | int repeats = 1; |
14 | if (argc >= 2) |
15 | repeats = atoi(argv[1]); |
16 | |
17 | std::string text((std::istreambuf_iterator<char>(std::cin)), |
18 | std::istreambuf_iterator<char>()); |
19 | |
20 | std::cout << "Text length: "<< text.size() << std::endl; |
21 | |
22 | Stopwatch timer; |
23 | std::string str1; |
24 | { |
25 | DB::WriteBufferFromString simple_buf(str1); |
26 | for (int i = 0; i < repeats; ++i) |
27 | { |
28 | simple_buf.write(text.data(), text.size()); |
29 | } |
30 | } |
31 | double t = timer.elapsedSeconds(); |
32 | std::cout << "Wrote to string in "<< t << "s at "<< text.size() / 1e6 * repeats / t << "MB/s."<< std::endl; |
33 | std::cout << "String length: "<< str1.size() << "("<< (str1.size() == text.size() * repeats ? "as ": "un") << "expected)"<< std::endl; |
34 | |
35 | timer.restart(); |
36 | |
37 | std::string str2; |
38 | { |
39 | DB::WriteBufferFromString simple_buf(str2); |
40 | for (int i = 0; i < repeats; ++i) |
41 | { |
42 | DB::WriteBufferValidUTF8 utf_buf(simple_buf); |
43 | utf_buf.write(text.data(), text.size()); |
44 | } |
45 | } |
46 | t = timer.elapsedSeconds(); |
47 | std::cout << "Wrote to UTF8 in "<< t << "s at "<< text.size() / 1e6 * repeats / t << "MB/s."<< std::endl; |
48 | std::cout << "String length: "<< str2.size() << "("<< (str2.size() == text.size() * repeats ? "as ": "un") << "expected)"<< std::endl; |
49 | } |
50 | catch (const DB::Exception & e) |
51 | { |
52 | std::cerr << e.what() << ", "<< e.displayText() << std::endl; |
53 | return 1; |
54 | } |
55 | |
56 | return 0; |
57 | } |
58 |