I want to record the time during every loop.
How to get the time elapsed with precision of microsecond or millisecond on c5515 with ccs4?
I have some code, the output is
0.000000 seconds
use difftime 4.000000
This is not good. difftime will give time difference in seconds. However, the duration part does not work at all. Is there a problem using CLOCKS_PER_SEC?
#include <stdio.h>
#include <time.h>
int main()
{
clock_t start, finish, start2, finish2;
double duration;
time(&start);
start2 = clock();
for ( int i = 0; i < 300; i++)
printf("%d\n",i);
time(&finish);
finish2 = clock();
duration = (double)((finish2 - start2) / CLOCKS_PER_SEC);
printf( "%f seconds\n", duration );
printf("use difftime %f\n",difftime(finish,start));
return 0;
}