всем, у меня есть проект на платформе windows, и я хочу измерить время выполнения нескольких функций через некоторое время l oop (рисунок 3), поэтому я создаю класс (называемый Benchmark, рисунок 1 заголовок и рисунок 2 - это исходный код), которые делают это, однако он выполняет время на каждом шаге (рис. 4), но я хочу знать, сколько времени программа тратит полностью на каждую функцию. Любая идея, пожалуйста.
// Benchmrak.cpp
#define time Now() std::chrono::high_resolution_clock::now();
#define duration(a) std::chrono::duration_cast<std::chrono::nanoseconds (a).count();
Benchmark:: Benchmark(std::string caller, bool start_running=false ) :_caller(caller), _elapsed(0), _running(false),average (0),count(0)
{
if (start_running ) start();
}
//-------------------------------------------------------
Benchmark:: ~Benchmark()
{
stop();
//average_time();
disp ();
}
//-------------------------------------------------------
void Benchmark:: start()
{
if (!_running) //=if (runing==false)
{
_start_time=timeNow();
_running = true;
}
}
//-------------------------------------------------------
void Benchmark:: stop()
{
if (_running )
{
stop_time=timeNow();
_elapsed= duration(stop_time - _start_time);
average =_elapsed;
_running = false;
count ;
}
}
void Benchmark:: disp()
{
std::cout<<std::fixed<<std::setprecision(4);
std::cout<<"Time taking for "<<_caller<<" is : "<< _elapsed /1.e9 <<"s\n";
// in another file.Cpp contain while loop
while( _continue )
{
//std::cout<<"Image number "<<m_imgIdx<<std::endl;
//read image
AbbeTIFFReader_getSampleData( m_tiff, mat.data, 0);
_continue = AbbeTIFFReader_readNext( m_tiff );
cv::add ( mat, matConcatenated, matConcatenated, cv::noArray(),CV_32FC1 );
Benchmark tim_1 ("LocalMean",true);
//local mean
cv::Mat mat_LocalMean = m_substractLocalMean(mat,15); //1st function
tim_1.stop();
//wavelet
double stdDev =0;
Benchmark tim_2("matWavel et",true);
cv::Mat matWavelet = m_WaveletFiltering (mat_LocalMean,stdDev); //2nd function
tim_2.stop();
//fast
Benchmark tim_3 ("fastLoc",true);
m_fastLoc(matWavelet,stdDev,1.,9,50); //3rd function
tim_3.stop();
tim_1.disp ();
tim_2.disp ();
tim_3.disp ();
m_imgIdx ;
// the exution
}`*********** iam in startLocalization function *************
void Localization::startLocalization()
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s
Time taking for LocalMean is : 0.0000s
Time taking for matWavel et is : 0.0000s
Time taking for fastLoc is : 0.0010s