2013-01-05 20:03:19 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Field.h>
|
2017-11-24 13:55:31 +00:00
|
|
|
#include <Common/FieldVisitors.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
|
|
|
|
#include <Common/Stopwatch.h>
|
|
|
|
#include <IO/WriteBufferFromFileDescriptor.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2013-01-05 20:03:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using namespace DB;
|
2015-10-12 07:05:54 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
FieldVisitorToString to_string;
|
2017-01-06 17:41:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Field field = UInt64(0);
|
|
|
|
std::cerr << applyVisitor(to_string, field) << std::endl;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
field = std::string("Hello, world!");
|
|
|
|
std::cerr << applyVisitor(to_string, field) << std::endl;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
field = Null();
|
|
|
|
std::cerr << applyVisitor(to_string, field) << std::endl;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Field field2;
|
|
|
|
field2 = field;
|
|
|
|
std::cerr << applyVisitor(to_string, field2) << std::endl;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2019-01-04 13:54:39 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
get<Array &>(field).push_back(field);
|
|
|
|
std::cerr << applyVisitor(to_string, field) << std::endl;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << (field < field2) << std::endl;
|
|
|
|
std::cerr << (field2 < field) << std::endl;
|
2013-01-08 21:32:16 +00:00
|
|
|
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
size_t n = argc == 2 ? parse<UInt64>(argv[1]) : 10000000;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Stopwatch watch;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
Array array(n);
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-01-04 13:54:39 +00:00
|
|
|
watch.restart();
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
|
|
|
array[i] = String(i % 32, '!');
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
|
|
|
<< "Set " << n << " fields (" << n * sizeof(array[0]) / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
|
|
|
|
<< n / watch.elapsedSeconds() << " elem/sec. (" << n * sizeof(array[0]) / watch.elapsedSeconds() / 1000000 << " MB/s.)"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-01-04 13:54:39 +00:00
|
|
|
watch.restart();
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t sum = 0;
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
|
|
|
sum += safeGet<const String &>(array[i]).size();
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
|
|
|
<< "Got " << n << " fields (" << n * sizeof(array[0]) / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
|
|
|
|
<< n / watch.elapsedSeconds() << " elem/sec. (" << n * sizeof(array[0]) / watch.elapsedSeconds() / 1000000 << " MB/s.)"
|
|
|
|
<< std::endl;
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << sum << std::endl;
|
|
|
|
}
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
watch.restart();
|
|
|
|
}
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
watch.stop();
|
2013-01-05 20:03:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
|
|
|
<< "Destroyed " << n << " fields (" << n * sizeof(Array::value_type) / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
|
|
|
|
<< n / watch.elapsedSeconds() << " elem/sec. (" << 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;
|
|
|
|
}
|
2015-10-12 07:05:54 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << "sizeof(Field) = " << sizeof(Field) << std::endl;
|
2015-10-12 07:05:54 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return 0;
|
2013-01-05 20:03:19 +00:00
|
|
|
}
|