-1
嘿我嘗試計數功能需要多長時間來執行 我這樣做是這樣的: Timer.cppQueryPerformanceCounter的返回負數
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;
}
任何人都可以告訴我,如果我這樣做是否正確?
'query.time1 - query.time2'將是負面的,如果'time2'是較大的,對不對? – 2013-03-20 18:12:56
正確,但我會如何實現兩個變量的差異? – Becca 2013-03-20 18:13:59
'query.time2 - query.time1' – 2013-03-20 18:14:41