1#include <iostream>
2#include <iomanip>
3#include <sstream>
4
5#include <Core/Field.h>
6#include <Common/FieldVisitors.h>
7
8#include <Common/Stopwatch.h>
9#include <IO/WriteBufferFromFileDescriptor.h>
10#include <IO/ReadHelpers.h>
11#include <DataTypes/DataTypeString.h>
12
13
14int main(int argc, char ** argv)
15{
16 using namespace DB;
17
18 FieldVisitorToString to_string;
19
20 Field field = UInt64(0);
21 std::cerr << applyVisitor(to_string, field) << std::endl;
22
23 field = std::string("Hello, world!");
24 std::cerr << applyVisitor(to_string, field) << std::endl;
25
26 field = Null();
27 std::cerr << applyVisitor(to_string, field) << std::endl;
28
29 Field field2;
30 field2 = field;
31 std::cerr << applyVisitor(to_string, field2) << std::endl;
32
33 {
34 Array array;
35 array.push_back(UInt64(123));
36 array.push_back(Int64(-123));
37 array.push_back(String("Hello"));
38 field = array;
39 std::cerr << applyVisitor(to_string, field) << std::endl;
40 }
41
42 get<Array &>(field).push_back(field);
43 std::cerr << applyVisitor(to_string, field) << std::endl;
44
45 std::cerr << (field < field2) << std::endl;
46 std::cerr << (field2 < field) << std::endl;
47
48
49 try
50 {
51 size_t n = argc == 2 ? parse<UInt64>(argv[1]) : 10000000;
52
53 Stopwatch watch;
54
55 {
56 Array array(n);
57
58 {
59 watch.restart();
60
61 for (size_t i = 0; i < n; ++i)
62 array[i] = String(i % 32, '!');
63
64 watch.stop();
65 std::cerr << std::fixed << std::setprecision(2)
66 << "Set " << n << " fields (" << n * sizeof(array[0]) / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
67 << n / watch.elapsedSeconds() << " elem/sec. (" << n * sizeof(array[0]) / watch.elapsedSeconds() / 1000000 << " MB/s.)"
68 << std::endl;
69 }
70
71 {
72 watch.restart();
73
74 size_t sum = 0;
75 for (size_t i = 0; i < n; ++i)
76 sum += safeGet<const String &>(array[i]).size();
77
78 watch.stop();
79 std::cerr << std::fixed << std::setprecision(2)
80 << "Got " << n << " fields (" << n * sizeof(array[0]) / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
81 << n / watch.elapsedSeconds() << " elem/sec. (" << n * sizeof(array[0]) / watch.elapsedSeconds() / 1000000 << " MB/s.)"
82 << std::endl;
83
84 std::cerr << sum << std::endl;
85 }
86
87 watch.restart();
88 }
89
90 watch.stop();
91
92 std::cerr << std::fixed << std::setprecision(2)
93 << "Destroyed " << n << " fields (" << n * sizeof(Array::value_type) / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
94 << n / watch.elapsedSeconds() << " elem/sec. (" << n * sizeof(Array::value_type) / watch.elapsedSeconds() / 1000000 << " MB/s.)"
95 << std::endl;
96 }
97 catch (const Exception & e)
98 {
99 std::cerr << e.what() << ", " << e.displayText() << std::endl;
100 return 1;
101 }
102
103 std::cerr << "sizeof(Field) = " << sizeof(Field) << std::endl;
104
105 return 0;
106}
107