最近需要测算软件计算FFT所需要的时间,所收集参考的资料:
点击(此处)折叠或打开
-
#include <stdio.h>
-
#include <stdlib.h> /* 包含标准库头文件 */
-
#include <sys/time.h>
-
-
int main(int argc, char **argv)
-
{
-
struct timeval start,stop,diff;
-
gettimeofday(&start,0);
-
//做你要做的事...
-
gettimeofday(&stop,0);
-
timeval_subtract(&diff,&start,&stop);
-
printf("总计用时:%d 微秒\n",diff.tv_usec);
-
}
-
-
/**
-
* 计算两个时间的间隔,得到时间差
-
* @param struct timeval* resule 返回计算出来的时间
-
* @param struct timeval* x 需要计算的前一个时间
-
* @param struct timeval* y 需要计算的后一个时间
-
* return -1 failure ,0 success
-
**/
-
int timeval_subtract(struct timeval* result, struct
timeval* x, struct timeval* y)
-
{
-
int nsec;
-
-
if ( x->tv_sec>y->tv_sec )
-
return -1;
-
-
if ( (x->tv_sec==y->tv_sec) && (x->tv_usec>y->tv_usec) )
-
return -1;
-
-
result->tv_sec = ( y->tv_sec-x->tv_sec );
-
result->tv_usec = ( y->tv_usec-x->tv_usec );
-
-
if (result->tv_usec<0)
-
{
-
result->tv_sec--;
-
result->tv_usec+=1000000;
-
}
-
-
return 0;
- }
本文介绍了一种使用C语言实现的方法来精确测量FFT计算所需的时间。通过利用<sys/time.h>库中的gettimeofday函数记录开始和结束时刻,并计算两者之差,从而得出执行FFT所需的具体时间。
884

被折叠的 条评论
为什么被折叠?



