#include #include #include #include #include #include #include "demangle.h" #include "ijk.h" const size_t B = 2, C = 3, N = 128; template void test_type(F& f) { T a[N][N], b[N][N], c[N][N]; for (size_t i = 0; i < N; ++i) for (size_t j = 0; j < N; ++j) { a[i][j] = 0; b[i][j] = B; c[i][j] = C; } const size_t R = 33; std::chrono::duration rep[R]; for (auto& r: rep) { auto start = std::chrono::high_resolution_clock::now(); f(a, b, c); auto stop = std::chrono::high_resolution_clock::now(); r = stop - start; } std::nth_element(rep, rep + R / 2, rep + R); std::cout << std::fixed << std::setprecision(2) << std::setw(8) << rep[R/2].count(); assert(a[N - 1][N - 1] == B * C * N * R); }; #define test_function(f) \ std::cout << std::setw(8) << #f; \ test_type< short>(f< short, N>); \ test_type< int>(f< int, N>); \ test_type< long>(f< long, N>); \ test_type< float>(f< float, N>); \ test_type< double>(f< double, N>); \ test_type(f); \ std::cout << std::endl int main() { const char *types[] = {"(ms)", "short", "int", "long", "float", "double", "ldouble"}; int count = 0; for (auto& i: types) { std::cout << std::setw(8) << i; ++count; } std::cout << std::endl; for (int i = 0; i < count; ++i) std::cout << std::setw(8) << "-------"; std::cout << std::endl; test_function(ijk); test_function(ikj); test_function(jik); test_function(jki); test_function(kij); test_function(kji); }