-1

関数の実行にかかる時間をカウントしようとしています 。Timer.cppのように実行しています。

long long int Timer :: clock1()
{
    QueryPerformanceCounter((LARGE_INTEGER*)&time1);
    return time1;
}
long long int Timer :: clock2()
{
    QueryPerformanceCounter((LARGE_INTEGER*)&time2);
    return time2;
}

main.cpp

#include "Timer.h"  //To allow the use of the timer class.

Timer query;

void print()
{
    query.clock1();
    //Loop through the elements in the array.
    for(int index = 0; index < num_elements; index++)
    {
        //Print out the array index and the arrays elements.
        cout <<"Index: " << index << "\tElement: " << m_array[index]<<endl;
    }
    //Prints out the number of elements and the size of the array.
    cout<< "\nNumber of elements: " << num_elements;
    cout<< "\nSize of the array: " << size << "\n";
    query.clock2();
    cout << "\nTime Taken : " << query.time1 - query.time2;
}

私がこれを正しく行っているかどうか誰かに教えてもらえますか?

4

2 に答える 2

2

開始時刻から終了時刻を引いています。

cout << "\nTime Taken : " << query.time1 - query.time2;

する必要があります

cout << "\nTime Taken : " << query.time2 - query.time1
于 2013-03-20T18:13:25.540 に答える
1

何かを 10 秒で開始し、30 秒で終了するとします。どのくらいかかりましたか?20秒。それを取得するには、次のようにし30 - 10ます。つまり、2 回目は 1 回目を減算します。

したがって、おそらくあなたが望む:

cout << "\nTime Taken : " << (query.time2 - query.time1);
于 2013-03-20T18:13:39.593 に答える