ClickHouse/dbms/Core/tests/field.cpp

107 lines
3.1 KiB
C++
Raw Normal View History

#include <iostream>
#include <iomanip>
#include <sstream>
#include <Core/Field.h>
#include <Common/FieldVisitors.h>
#include <Common/Stopwatch.h>
#include <IO/WriteBufferFromFileDescriptor.h>
#include <IO/ReadHelpers.h>
#include <DataTypes/DataTypeString.h>
int main(int argc, char ** argv)
{
using namespace DB;
FieldVisitorToString to_string;
Squashed commit of the following: commit c567d4e1fe8d54e6363e47548f1e3927cc5ee78f Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:35:01 2017 +0300 Style [#METR-2944]. commit 26bf3e1228e03f46c29b13edb0e3770bd453e3f1 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:33:11 2017 +0300 Miscellaneous [#METR-2944]. commit eb946f4c6fd4bb0e9e5c7fb1468d36be3dfca5a5 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:30:19 2017 +0300 Miscellaneous [#METR-2944]. commit 78c867a14744b5af2db8d37caf7804fc2057ea51 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 20:11:41 2017 +0300 Miscellaneous [#METR-2944]. commit 6604c5c83cfcedc81c8da4da026711920d5963b4 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:56:15 2017 +0300 Miscellaneous [#METR-2944]. commit 23fbf05c1d4bead636458ec21b05a101b1152e33 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:47:52 2017 +0300 Miscellaneous [#METR-2944]. commit 98772faf11a7d450d473f7fa84f8a9ae24f7b59b Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:46:05 2017 +0300 Miscellaneous [#METR-2944]. commit 3dc636ab9f9359dbeac2e8d997ae563d4ca147e2 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:39:46 2017 +0300 Miscellaneous [#METR-2944]. commit 3e16aee95482f374ee3eda1a4dbe9ba5cdce02e8 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:38:03 2017 +0300 Miscellaneous [#METR-2944]. commit ae7e7e90eb1f82bd0fe0f887708d08b9e7755612 Author: Alexey Milovidov <milovidov@yandex-team.ru> Date: Fri Jan 6 19:34:15 2017 +0300 Miscellaneous [#METR-2944].
2017-01-06 17:41:19 +00:00
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;
}
get<Array &>(field).push_back(field);
std::cerr << applyVisitor(to_string, field) << std::endl;
std::cerr << (field < field2) << std::endl;
std::cerr << (field2 < field) << std::endl;
2013-01-08 21:32:16 +00:00
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 (" << 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;
}
{
watch.restart();
size_t sum = 0;
for (size_t i = 0; i < n; ++i)
sum += safeGet<const String &>(array[i]).size();
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;
std::cerr << sum << std::endl;
}
watch.restart();
}
watch.stop();
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;
}
std::cerr << "sizeof(Field) = " << sizeof(Field) << std::endl;
return 0;
}