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++;
}
我在做什么错?启动和停止时间总是相同...