1 | #include <string> |
2 | |
3 | #include <iostream> |
4 | #include <fstream> |
5 | |
6 | #include <Core/Types.h> |
7 | #include <Common/Stopwatch.h> |
8 | #include <Common/formatReadable.h> |
9 | #include <IO/readFloatText.h> |
10 | #include <IO/WriteHelpers.h> |
11 | #include <IO/Operators.h> |
12 | #include <IO/ReadBufferFromFileDescriptor.h> |
13 | #include <IO/WriteBufferFromFileDescriptor.h> |
14 | #include <Compression/CompressedReadBuffer.h> |
15 | |
16 | |
17 | /** How to test: |
18 | |
19 | # Prepare data |
20 | |
21 | $ clickhouse-local --query="SELECT number FROM system.numbers LIMIT 10000000" > numbers1.tsv |
22 | $ clickhouse-local --query="SELECT number % 10 FROM system.numbers LIMIT 10000000" > numbers2.tsv |
23 | $ clickhouse-local --query="SELECT number / 1000 FROM system.numbers LIMIT 10000000" > numbers3.tsv |
24 | $ clickhouse-local --query="SELECT rand64() / 1000 FROM system.numbers LIMIT 10000000" > numbers4.tsv |
25 | $ clickhouse-local --query="SELECT rand64() / 0xFFFFFFFF FROM system.numbers LIMIT 10000000" > numbers5.tsv |
26 | $ clickhouse-local --query="SELECT log(rand64()) FROM system.numbers LIMIT 10000000" > numbers6.tsv |
27 | $ clickhouse-local --query="SELECT 1 / rand64() FROM system.numbers LIMIT 10000000" > numbers7.tsv |
28 | $ clickhouse-local --query="SELECT exp(rand() / 0xFFFFFF) FROM system.numbers LIMIT 10000000" > numbers8.tsv |
29 | $ clickhouse-local --query="SELECT number FROM system.numbers LIMIT 10000000" > numbers1.tsv |
30 | $ clickhouse-local --query="SELECT toString(rand64(1)) || toString(rand64(2)) || toString(rand64(3)) || toString(rand64(4)) FROM system.numbers LIMIT 10000000" > numbers9.tsv |
31 | $ clickhouse-local --query="SELECT toString(rand64(1)) || toString(rand64(2)) || '.' || toString(rand64(3)) || toString(rand64(4)) FROM system.numbers LIMIT 10000000" > numbers10.tsv |
32 | |
33 | # Run test |
34 | |
35 | $ for i in {1..10}; do echo $i; time ./read_float_perf 2 < numbers$i.tsv; done |
36 | |
37 | */ |
38 | |
39 | |
40 | using namespace DB; |
41 | |
42 | |
43 | template <typename T, void F(T&, ReadBuffer&)> |
44 | void NO_INLINE loop(ReadBuffer & in, WriteBuffer & out) |
45 | { |
46 | T sum = 0; |
47 | T x = 0; |
48 | |
49 | Stopwatch watch; |
50 | |
51 | while (!in.eof()) |
52 | { |
53 | F(x, in); |
54 | in.ignore(); |
55 | sum += x; |
56 | } |
57 | |
58 | watch.stop(); |
59 | out << "Read in " << watch.elapsedSeconds() << " sec, " << formatReadableSizeWithBinarySuffix(in.count() / watch.elapsedSeconds()) << "/sec, result = " << sum << "\n" ; |
60 | } |
61 | |
62 | |
63 | int main(int argc, char ** argv) |
64 | try |
65 | { |
66 | int method = 0; |
67 | if (argc >= 2) |
68 | method = parse<int>(argv[1]); |
69 | |
70 | using T = Float64; |
71 | |
72 | ReadBufferFromFileDescriptor in(STDIN_FILENO); |
73 | WriteBufferFromFileDescriptor out(STDOUT_FILENO); |
74 | |
75 | if (method == 1) loop<T, readFloatTextPrecise>(in, out); |
76 | if (method == 2) loop<T, readFloatTextFast>(in, out); |
77 | if (method == 3) loop<T, readFloatTextSimple>(in, out); |
78 | |
79 | return 0; |
80 | } |
81 | catch (const Exception & e) |
82 | { |
83 | std::cerr << e.what() << ", " << e.displayText() << std::endl; |
84 | return 1; |
85 | } |
86 | |