Jul 5, 2015 at 3:54am Jul 5, 2015 at 3:54am UTC
I want to evaluate how much time a function in an OpenCV program takes to run and how much time a similar function implemented in c++ will take? Which library and which start time and end time functions that i can use, in which both the library and the time functions are compatible with both OpenCV programs and c++ programs.
Jul 5, 2015 at 4:35am Jul 5, 2015 at 4:35am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// return pair of elapsed processor_time, elapsed wall clock time (both in milliseconds)
template < typename FN, typename ... ARGS >
std::pair<double ,double > time_it( FN&& fn, ARGS&& ... args )
{
using wall_clock = typename std::conditional< std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock,
std::chrono::steady_clock >::type ;
const auto wc_start = wall_clock::now() ;
const auto pc_start = std::clock() ;
std::forward<FN>(fn)( std::forward<ARGS>(args)... ) ; // call the function
const auto pc_end = std::clock() ;
const auto wc_end = wall_clock::now() ;
return { ( pc_end - pc_start ) * 1000.0 / CLOCKS_PER_SEC, // processor time millisecs
std::chrono::duration_cast<std::chrono::milliseconds>( wc_end - wc_start ).count() } ;
}
http://coliru.stacked-crooked.com/a/babd699c5e6f8c20
Last edited on Jul 5, 2015 at 4:42am Jul 5, 2015 at 4:42am UTC