0
我有一個計時器功能(用於輪詢),我想調用每個1uS,但我也想確保有足夠的時間讓其他任務運行,因此我想測量它花費的時間執行此功能。爲此,我想我可以在我的功能開始時和最後使用clock_gettime()
。現在我的問題是,返回的兩次總是相同的,我只是不相信我的函數在不到1納秒內運行 - 這不是可能的時期。 CPU的時鐘頻率爲800MHz。 我的代碼:測量定時器功能的持續時間
struct timespec tempTime_start;
struct timespec tempTime_stop;
static int print = 0;
if(clock_gettime(CLOCK_REALTIME, &tempTime_start))
printf("Error in clock_gettime(): %s",strerror(errno));
...
...MY FUNCTION...
int i = 0;
for (i = 0;i<100000;i++);
if(clock_gettime(CLOCK_REALTIME, &tempTime_stop))
printf("Error in clock_gettime(): %s",strerror(errno));
if (print <= 100){
printf("%dDuration: %d\n",print,(tempTime_stop.tv_nsec - tempTime_start.tv_nsec));
printf("Start: %d\n",tempTime_start.tv_nsec);
printf("Stop: %d\n",tempTime_stop.tv_nsec);
print++;
}
我在做什麼錯?啓動和停止時間總是相同...