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