mercredi 21 octobre 2015

moving from c# to C++ testing / timings QueryPerformanceCounter vs clock() confusing results

In C# i am using Stopwatch class i can get the ticks, and millsecs no problems.

Now that i am testing codes while learning c++ i try to get measurements and i don't know where the results are the c# Stopwatch solution equivalent, i tried to search but the information is to broad and i couldn't find an absolute solution.

double PCFreq = 0.0;
__int64 CounterStart = 0;
void StartCounter()
{
    LARGE_INTEGER li;
    if(!QueryPerformanceFrequency(&li))
    std::cout << "QueryPerformanceFrequency failed!\n";
    PCFreq = double(li.QuadPart)/1000.0;
    QueryPerformanceCounter(&li);
    CounterStart = li.QuadPart;
}

double GetCounter()
{
    LARGE_INTEGER li;
    QueryPerformanceCounter(&li);
    return double(li.QuadPart-CounterStart)/PCFreq;
}

As that gives me two different results and i tend to belive the clock (:

start =  StartCounter()
//some function or for loop
end = GetCounter()
marginPc = end - start;

start = clock();
// ...same
end= clock();
marginClck = end - start;

std::cout<< "Res Pc: " << marginPc << "\r\nRes Clck: " marginClck<< std::endl;

to the clock version i tried both unsigned int and double but the results was still different what is the proper/ equivalent Stopwatch ?

Aucun commentaire:

Enregistrer un commentaire