1 | #include <iostream> |
---|---|
2 | #include <iomanip> |
3 | |
4 | #include <IO/ReadHelpers.h> |
5 | #include <IO/ReadBufferFromFileDescriptor.h> |
6 | |
7 | #include <Common/Stopwatch.h> |
8 | |
9 | |
10 | namespace test |
11 | { |
12 | template <typename T> |
13 | void readIntText(T & x, DB::ReadBuffer & buf) |
14 | { |
15 | bool negative = false; |
16 | x = 0; |
17 | |
18 | if (unlikely(buf.eof())) |
19 | DB::throwReadAfterEOF(); |
20 | |
21 | if (is_signed_v<T> && *buf.position() == '-') |
22 | { |
23 | ++buf.position(); |
24 | negative = true; |
25 | } |
26 | |
27 | if (*buf.position() == '0') |
28 | { |
29 | ++buf.position(); |
30 | return; |
31 | } |
32 | |
33 | while (!buf.eof()) |
34 | { |
35 | if ((*buf.position() & 0xF0) == 0x30) |
36 | { |
37 | x *= 10; |
38 | x += *buf.position() & 0x0F; |
39 | ++buf.position(); |
40 | } |
41 | else |
42 | break; |
43 | } |
44 | |
45 | if (is_signed_v<T> && negative) |
46 | x = -x; |
47 | } |
48 | } |
49 | |
50 | |
51 | int main(int, char **) |
52 | { |
53 | try |
54 | { |
55 | DB::ReadBufferFromFileDescriptor in(STDIN_FILENO); |
56 | Int64 n = 0; |
57 | size_t nums = 0; |
58 | |
59 | Stopwatch watch; |
60 | |
61 | while (!in.eof()) |
62 | { |
63 | DB::readIntText(n, in); |
64 | in.ignore(); |
65 | |
66 | //std::cerr << "n: " << n << std::endl; |
67 | |
68 | ++nums; |
69 | } |
70 | |
71 | watch.stop(); |
72 | std::cerr << std::fixed << std::setprecision(2) |
73 | << "Read "<< nums << " numbers ("<< in.count() / 1000000.0 << " MB) in "<< watch.elapsedSeconds() << " sec., " |
74 | << nums / watch.elapsedSeconds() << " num/sec. ("<< in.count() / watch.elapsedSeconds() / 1000000 << " MB/s.)" |
75 | << std::endl; |
76 | } |
77 | catch (const DB::Exception & e) |
78 | { |
79 | std::cerr << e.what() << ", "<< e.displayText() << std::endl; |
80 | return 1; |
81 | } |
82 | |
83 | return 0; |
84 | } |
85 |