This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

time execution

Hello everyone,

I would like to calculate the execution time of a method, for that I use clock (). The problem is that the time returned is always zero.

I use CCS and the target is C64x+. 

any help please.

Serina.

  • Hi Serina,

    CCS have a feature called profiler that will count CPU clocks.

    You can set a breakpoint before a method and after a method. Enable the profiler for CPU clocks. Clear the count and hit run. When the processor reaches the breakpoint, CCS will display the number of CPU clocks that have transpired.

    Check out below mentioned clock profiling Wiki.
    processors.wiki.ti.com/.../Profile_clock_in_CCS
  • Hi Arvind
    thanks for your reply, i used this feature and TSLC command with a simple example to measure the number of cycles, but i didn't find the same results :(
    code:
    #include "c6x.h" // needed
    #include <iostream>
    using namespace std;
    #include <iostream>
    #include <ctime>

    int start, stop;
    int main(){
    TSCL = 0;
    start = TSCL;
    float tab1[10]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.1};
    float tab2[10]={16.1,15.2,17.3,17.4,10.5,20.6,30.7,40.8,30.9,11.1};

    int k;

    cout<<"Somme de 2 tableaux"<<endl;
    for (k=0 ;k<1; k++) {

    float S=0;
    S+=tab2[k]+tab1[k];


    cout<<"S : sommes des elements des deux premiers tableaux :"<<S<<endl;

    }

    stop = TSCL;
    stop -= start; // stop will have the total number of CPU cycles
    cout<<"total number of CPU cycles = "<<stop<<endl;
    }

    =>result:

    *****on console:
    total number of CPU cycles = 76844.
    *****profil clock: 56,13
    the two result are so different ,I don't know what's the problem, can you help me .
    thanks in advance.

    Serina.
  • Serina,

    Since you did not state where your breakpoints were for the CCS Profiler Clock or the exact steps you went through to get that number, it is difficult to know how to explain the difference. But personally, if you are already using TSCL then there is no reason to use the CCS clock. TSCL gives a perfect result when used correctly.

    By being used correctly, I mean that you have to understand that it is a free-running clock that gets started once after device reset and it will roll-over to 0 after 4 seconds if you are running at 1GHz (scale that time for other DSP clock frequencies). You can solve that problem by using the full 64-bit TSCH/TSCL, but it is much easier to stay with TSCL and just recognize the possibility of a roll-over. The line TSCL=0 does not clear the TSCL counter, but it will start it running from 0 if it is not already running; if it is already running, then TSCL=0 has no negative effect.

    Since your benchmark code includes CIO, and since you do not show any of the console output other than the line you wanted to point us to ("total number of CPU cycles"), I assume the display is edited. Not an issue that I can think of, but it could be interesting to include TSCL in the "S : sommes des elements ..." output to give you some idea of the progress of clock cycles and proof whether TSCL is starting at 0 every time you run the test.

    But having the CIO in there definitely means you are not optimizing, yet. CIO will always be very slow, so it is never used in code that is meant to be optimized for significantly fastest performance. Again, this is not a problem since you are currently trying to get valid numbers and do not really care what those numbers are.

    After saying all of that, the 76844 cycles to run your loop twice is easily a real and valid number resulting from this code execution.

    Sorry that I have no idea about the nature of the CCS clock in this case.

    If you want to pursue the clock count from TSCL, we can do that here. If you want to pursue the CCS profile clock, we can move this thread to the E2E Code Composer Forum. Or you can do both by posting a new question on the E2E Code Composer Forum and continuing this discussion here. So many options.

    Regards,
    RandyP
  • HI Serina
    Using break point and measure the CPU cycles is good but if you are using optimization ( i.e. -o3 ) from build option it will not give an accurate result because you me not be able to but the break points in the line that you want to but it in .
    my suggestion it to use TSCL as follow
    1- #include "c6x.h" to include the timing functions
    2- Define an 64 bit variable for example start_time , end_time and diff_time
    3- use start_time = _itoll (TSCH, TSCL); before the section that you want to measure it's consumption/timing
    4- use end_time = _itoll (TSCH, TSCL); after the section that you want to measure it's consumption/timing
    5- find the difference between the two variables diff_time = end_time-start_time;


    Best Regards
    Abdo