原文:
如何測試程序在DSP上的運行時間?
1. TI DSP編譯環境CCS3.3, 在profiler菜單中,選擇Enable Clock和view clock,在view clock窗口中可以看到程序運行的時間/週期(時鐘)數。
在view clock窗口中第2行顯示的時間就是程序從第1行所在位置到第2行位置的時間,也就是你要測定的時間。
缺點:時間cycle數據不準確,比實際的要大。如果用profiler得到的數據比你的要求好要少的話,那就說明已經達到了要求。
克服方法:(1)多次統計;
(2)測量之前重新使能 Enable Clock和view clock 。
2. 使用clock 測試程序運行時間
#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>