G
G
Giawow2015-04-06 18:20:44
Time Management
Giawow, 2015-04-06 18:20:44

Measuring the time of a section of code?

how to measure the execution time of a piece of code? Best in nanoseconds. I tried clock and GetTickCount, but they do not return the time, but the number of processor ticks. I found a chrono library, but there is no documentation in Russian .. Can anyone help with advice?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel K, 2015-04-06
@PavelK

Labels or something correctly put and the language would not hurt to specify.

LARGE_INTEGER freq;
    LARGE_INTEGER t1;
    LARGE_INTEGER t2;
    if(QueryPerformanceFrequency(&freq))
    {
        QueryPerformanceCounter(&t1);
        ..................................................
        QueryPerformanceCounter(&t2);
        double dt = t2.QuadPart - t1.QuadPart;
        double elapsed_time = 1000 * dt / freq.QuadPart; //-- время в миллисекундах
    }

But depending on the debug / release, the time is very different.

D
Dmitry, 2015-04-06
@hsc

For such tasks, a profiler was invented.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question