From 3c03d7c3720c44052f1e729b543feeb7b743a7cd Mon Sep 17 00:00:00 2001 From: Michael Kolupaev Date: Tue, 18 Feb 2014 14:14:37 +0400 Subject: [PATCH] clickhouse: added a program to measure logical functions performance. [#METR-9599] --- .../tests/logical_functions_performance.cpp | 376 ++++++++++++++++++ 1 file changed, 376 insertions(+) create mode 100644 dbms/src/Functions/tests/logical_functions_performance.cpp diff --git a/dbms/src/Functions/tests/logical_functions_performance.cpp b/dbms/src/Functions/tests/logical_functions_performance.cpp new file mode 100644 index 00000000000..e1a9c5e3625 --- /dev/null +++ b/dbms/src/Functions/tests/logical_functions_performance.cpp @@ -0,0 +1,376 @@ +#include +#include +#include +#include + + +namespace DB +{ + +template +struct AndImpl +{ + static inline UInt8 apply(UInt8 a, B b) + { + return a && b; + } +}; + +template +struct OrImpl +{ + static inline UInt8 apply(UInt8 a, B b) + { + return a || b; + } +}; + +template +struct XorImpl +{ + static inline UInt8 apply(UInt8 a, B b) + { + return (!a) != (!b); + } +}; + + +typedef ColumnVector::Container_t UInt8Container; +typedef std::vector *> UInt8ColumnPtrs; + +template +struct AssociativeOperationImpl +{ + /// Выбрасывает N последних столбцов из in (если их меньше, то все) и кладет в result их комбинацию. + static void execute(UInt8ColumnPtrs & in, UInt8Container & result) + { + if (N > in.size()){ + AssociativeOperationImpl::execute(in, result); + return; + } + + AssociativeOperationImpl operation(in); + in.erase(in.end() - N, in.end()); + + size_t n = result.size(); + for (size_t i = 0; i < n; ++i) + { + result[i] = operation.apply(i); + } + } + + const UInt8Container & vec; + AssociativeOperationImpl continuation; + + /// Запоминает последние N столбцов из in. + AssociativeOperationImpl(UInt8ColumnPtrs & in) + : vec(in[in.size() - N]->getData()), continuation(in) {} + + /// Возвращает комбинацию значений в i-й строке всех столбцов, запомненных в конструкторе. + inline UInt8 apply(size_t i) const + { + //return Op::apply(vec[i], continuation.apply(i)); + return vec[i] && continuation.apply(i); + } +}; + +template +struct AssociativeOperationImpl +{ + static void execute(UInt8ColumnPtrs & in, UInt8Container & result) + { + throw Exception("Logical error: AssociativeOperationImpl::execute called", ErrorCodes::LOGICAL_ERROR); + } + + const UInt8Container & vec; + + AssociativeOperationImpl(UInt8ColumnPtrs & in) + : vec(in[in.size() - 1]->getData()) {} + + inline UInt8 apply(size_t i) const + { + return vec[i]; + } +}; + + +template