How to measure time?

I know that there are many topics to find the code transit time, and I read a lot, but I'm really confused. I decided to use a high-resolution clock and ran this code to find out how many times a second the clock is ticking

cout << chrono::high_resolution_clock::period::den << endl;
output:10000000

and then I determined the start time and end time as shown below

int main()
{
    auto begin = std::chrono::high_resolution_clock::now();
    .
    .
    .
    .
    auto end = std::chrono::high_resolution_clock::now();
    cout<<"RUN TIME IS :"<<endl;
    std::cout << std::chrono:: duration_cast <chrono:: nanoseconds>(end-begin).count() << "ns" << std::endl;
    system("PAUSE");
    //**********************************************************
    return 0;
}

but in most cases the output is 0, but the code is more than 2000 lines, I spend a lot of time, but the problem has not yet been solved. So please let me know is this a good way to determine downtime? And what happened to my code? I am using VS2012 another question is that I want to measure the time it takes to calculate the problem, and I'm not sure which one I should measure (system time, user time or real time)? Thank you in advance

0
1

... " ", .

, Windows API:

API- QueryPerformanceCounter, .

+2

Source: https://habr.com/ru/post/1691356/


All Articles