DSPRelated.com
Forums

How to use clock() function to get the processing time

Started by Li Bing August 29, 2005
HI, all DSP friends I am using C6711 Device Cycles Accurate Simulator in CCS 3.0 IDE. I want to
use clock() function to obtain processing time of a code, I used a sample
code from CCS manual , but can not get the desired results, the result is
always 0. The following is the code. Anybody can give me some hint about
using clock() function to get the processing time for a code.

You help is great appreciated.
Regards
Li Bing

#include <stdio.h>
#include <time.h>

main()
{
clock_t start;
clock_t overhead;
clock_t elapsed;

/* Calculate the overhead from calling clock() */

start = clock();
overhead = clock() - start;

/* Calculate the elapsed time */

start = clock();
puts("Hello, world");
elapsed = clock() - start - overhead;

printf("Time = %ld cycles\n", (long)elapsed);
}