之前在VS下面用函数clock_t可以算出程序的运行时间,但是在CCS下面的时候,每次运行的时间都是0,是因为不支持这个函数么,网上查了很多都没找到合适的方法,求指教一下怎么在CCS下面显示程序的运行时间呢?
Shine:
用TSCH, TSCL计算。类似于下面这种
void main() { unsigned long long t1, t2; … TSCL = 0; // Initiate CPU timer by writing any val to TSCL … t1 = _itoll( TSCH, TSCL ); // benchmark snapshot of free-running ctr my_code_to_benchmark(); t2 = _itoll( TSCH, TSCL ); // benchmark snapshot of free-running ctr printf("# cycles == %ld\n", (t2-t1));}
yuanchao gan:
回复 Shine:
能不能给出一个具体的demo啊,因为像TSCL,TSCH这样怎么初始化,需要导入哪些包之类的
#include <stdio.h>#include <stdlib.h>#include "c6x.h"void test(){ int a = 0,i; for (i = 0; i<10000000; i++) a++; }int main(){ unsigned long long t1,t2; int i; extern __cregister volatile unsigned int TSCL; extern __cregister volatile unsigned int TSCH; t1 = _itoll(TSCH,TSCL);//#pragma omp parallel for for (i = 0; i<100; i++) test(); t2 = _itoll(TSCH,TSCL); printf("Run time == %ld\n",(t2-t1)); }
我这个没输出,没反应。怎么回事呢
yuanchao gan:
回复 yuanchao gan:
发现应该时数据过大了的问题