//----------------------------------------------------------------------------- // medir-nulo.cc //----------------------------------------------------------------------------- #include "nulo.h" #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 << " mínimo: " << 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[]) { #ifdef __has_include #if __has_include() test(usuario, "hebra usuario nula:"); #endif // __has_include #endif // __has_include() #ifdef __has_include #if __has_include() test(hibrida, "hebra híbrida nula:"); #endif // __has_include #endif // __has_include() test(nucleo, " hebra núcleo nula:"); test(proceso, " proceso nulo:"); } //-----------------------------------------------------------------------------