#include <time.h>
clock_t start,stop,overhead,t;
start=clock();
stop=clock();
overhead=start-stop;
start=clock();
****************************
中间是要测试的代码
****************************
stop=clock();
t=stop-start-overhead;
在profiler中设置Enable Clock以及时钟周期,完了单步运行后就能看见结果。
3. 利用TSCL和TSCH来测量DSP程序运行时间
#include <c6x.h>
#include <stdio.h>
void main()
{
unsigned long long start;
unsigned long long end;
TSCH=0;//Very important! Enable the registers.
TSCL=0; //Very important! Enable the registers.
start = _itoll (TSCH, TSCL);
//start = TSCL;
...
end = _itoll (TSCH, TSCL);
//end = TSCL;
printf("%d DSP-cycles\n",end-start);
}
DSP开发,测量某个函数或某段代码的cycles消耗是经常要做的事情,常用的profiling和clock()一般在simulation下使用。其实在c64x+ core上有两个计数寄存器TSCL/TSCH,它们与CPU同频,共同表示一个64-bit数,CPU运行一个cycle,该寄存器就加1,因此可以用它们来准确的测量cpu在某个执行段中消耗的cycles。一般我们只会用到TSCL这个寄存器,而TSCH是高32位,除非测试整个工程,一般用不到它。
4. 使用方法:长时间宽范围时钟测定
unsigned long long t1,t2;
t1=_itoll(TSCH,TSCL);
code_wait_test;
t2=_itoll(TSCH,TSCL);
printf(“#cycle=%d”,t2-t1);
短时间(7秒)窄范围时钟测定:
T1=TSCL;
…process code …
T2=TSCL;
Printf(“#cycle=%d”,t2-t1);
5. 采用biosAPI方式
LgUns time1=CLK_gethtime();
…process code …
LgUns time2=CLK_gethtime();
Cpucycles=(time2-time1)*CLK_cpucyclePerhtime;
Prinf(“#cycle=%d”,Cpucycle);
<如果遇到问题,可以技术交流>
<联系方式:QQ 1279682290>