我在qnx momemntics上運行以下代碼。將clock_gettime移植到窗口
#define BILLION 1000000000L;
struct timespec start_time;
struct timespec stop_time;
void start MyTestFunc() {
//Initialize the Test Start time
clock_gettime(CLOCK_REALTIME,&start_time)
// ... additonal code.
cout << "The exectuion time of func "<< calculateExecutionTime();
}
double calculateExecutionTime()
{
clock_gettime(CLOCK_REALTIME,&stop_time);
double dSeconds = (stop_time.tv_sec - start_time.tv_sec);
double dNanoSeconds = (double)(stop_time.tv_nsec - start_time.tv_nsec)/BILLION;
return dSeconds + dNanoSeconds;
}
現在我想將上面的代碼移植到windows。任何人都可以提供示例代碼。
謝謝!
檢查一些選項在http://stackoverflow.com/questions/275004/c-timer-function-to-provide-time-in-nano-seconds – pmg 2011-03-23 11:20:26