//----------------------------------------------------------------------------- // medir-nulo.cc //----------------------------------------------------------------------------- #include "nulo.h" #include #include #include #include #include #include #include #include #include //----------------------------------------------------------------------------- template void test(F &f, const char *msg) { const int n = 999, w = 7; std::chrono::duration rep[n]; 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 + n / 2, rep + n); std::cout << msg << " minimo: " << std::fixed << std::setprecision(2) << std::setw(w) << std::min_element(rep, rep + n)->count() << "µs" << " mediana: " << std::fixed << std::setprecision(2) << std::setw(w) << rep[n / 2].count() << "µs" << " máximo: " << std::fixed << std::setprecision(2) << std::setw(w) << std::max_element(rep, rep + n)->count() << "µs" << std::endl; } //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { test(usuario, "hebra usuario nula:"); test(nucleo, " hebra nucleo nula:"); test(proceso, " proceso nulo:"); } //-----------------------------------------------------------------------------