开发环境DM8127 + ipnc-rdk 3.5,想测试DSP中程序的运行时间,测试代码如下:
clock_t start, finish;
double dTime_1, dTime_2;
start = clock();
for(i=0;i<10000;i++)
{
j=2+2;
}
finish = clock();
dTime_1 = ((finish – start) / (double)CLOCKS_PER_SEC);
Vps_printf("%d: start = %u, finish = %u", __LINE__, start, finish);
Vps_printf("%d: dTime_1 = %f", __LINE__, dTime_1);
start = clock();
for(i=0;i<10000;i++)
{
j=2+2;
}
finish = clock();
dTime_2 = ((finish – start) / (double)CLOCKS_PER_SEC);
Vps_printf("%d: start = %u, finish = %u", __LINE__, start, finish);
Vps_printf("%d: dTime_2 = %f", __LINE__, dTime_2);
若是循环运行上述代码,运行结果有两种情况,第一种是:
[c6xdsp ] 603: start = 127993, finish = 32766457
[c6xdsp ] 604: dTime_1 = 0.163192
[c6xdsp ] 613: start = 4093245945, finish = 4193909241
[c6xdsp ] 614: dTime_2 = 0.503316
这种结果的问题是dTime_1和dTime_2差别很大,但是从程序分析,两者应该差不多。
第二种结果是:
[c6xdsp ] 603: start = 127993, finish = 32766457
[c6xdsp ] 604: dTime_1 = 0.163192
[c6xdsp ] 613: start = 127993, finish = 32766457
[c6xdsp ] 614: dTime_2 = 0.163192
得到与第一种结果完全不同的数值。
这是为什么呢?应该怎么去计算DSP程序的运行时间呢?
Huchong Li:
另外,测试中还发现,clock()函数返回的最大值不会超过4193909241
Huchong Li:
回复 Chris Meng:
好的,谢谢!!!