#include "ijk.h" #include #include #include #include #include #include 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(f); \ std::cout << std::endl; int main() { const char *types[] = {"(ms)", "int"}; for (auto &i : types) std::cout << std::setw(8) << i; std::cout << std::endl; for (size_t i = 0; i < sizeof(types)/sizeof(char*); ++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); }