#include #include #include #include const size_t N = 5'000; int matriz[N][N]; void f1() { for (size_t i = 0; i < N; ++i) for (size_t j = 0; j < N; ++j) matriz[i][j] = 0; } void f2() { for (size_t i = 0; i < N; ++i) for (size_t j = 0; j < N; ++j) matriz[j][i] = 0; } template void test(F& f, const char* s) { const size_t R = 11; std::chrono::duration rep[R]; for (auto& r: rep) { auto start = std::chrono::high_resolution_clock::now(); f(); auto stop = std::chrono::high_resolution_clock::now(); r = stop - start; } std::nth_element(rep, rep + R / 2, rep + R); std::cout << s << "\tmin: " << std::fixed << std::setprecision(2) << std::setw(8) << std::min_element(rep, rep + R)->count() << "\tmedian: " << std::fixed << std::setprecision(2) << std::setw(8) << rep[R/2].count() << "ms" << std::endl; } int main() { test(f1, "f1"); test(f2, "f2"); }