ClickHouse/dbms/src/Core/tests/field.cpp

102 lines
2.8 KiB
C++
Raw Normal View History

#include <iostream>
#include <iomanip>
#include <sstream>
#include <DB/Core/Field.h>
2015-10-05 00:44:40 +00:00
#include <DB/Common/Stopwatch.h>
#include <DB/DataStreams/TabSeparatedRowOutputStream.h>
#include <DB/IO/WriteBufferFromFileDescriptor.h>
#include <DB/DataTypes/DataTypeString.h>
int main(int argc, char ** argv)
{
2013-01-08 21:32:16 +00:00
DB::FieldVisitorToString to_string;
DB::Field field = DB::UInt64(0);
std::cerr << DB::apply_visitor(to_string, field) << std::endl;
field = std::string("Hello, world!");
std::cerr << DB::apply_visitor(to_string, field) << std::endl;
field = DB::Null();
std::cerr << DB::apply_visitor(to_string, field) << std::endl;
DB::Field field2;
field2 = field;
std::cerr << DB::apply_visitor(to_string, field2) << std::endl;
2013-10-11 18:38:35 +00:00
DB::Array array;
array.push_back(DB::UInt64(123));
array.push_back(DB::Int64(-123));
array.push_back(DB::String("Hello"));
field = array;
std::cerr << DB::apply_visitor(to_string, field) << std::endl;
2013-10-11 18:38:35 +00:00
DB::get<DB::Array &>(field).push_back(field);
std::cerr << DB::apply_visitor(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
{
2013-06-21 21:05:16 +00:00
size_t n = argc == 2 ? DB::parse<UInt64>(argv[1]) : 10000000;
Stopwatch watch;
{
2013-10-11 18:38:35 +00:00
DB::Array array(n);
{
Stopwatch watch;
for (size_t i = 0; i < n; ++i)
array[i] = DB::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;
}
{
Stopwatch watch;
size_t sum = 0;
for (size_t i = 0; i < n; ++i)
sum += DB::safeGet<const DB::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)
2013-10-11 18:38:35 +00:00
<< "Destroyed " << n << " fields (" << n * sizeof(DB::Array::value_type) / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
<< n / watch.elapsedSeconds() << " elem/sec. (" << n * sizeof(DB::Array::value_type) / watch.elapsedSeconds() / 1000000 << " MB/s.)"
<< std::endl;
}
catch (const DB::Exception & e)
{
std::cerr << e.what() << ", " << e.displayText() << std::endl;
return 1;
}
2013-01-08 21:32:16 +00:00
std::cerr << "sizeof(Field) = " << sizeof(DB::Field) << std::endl;
return 0;
}