What is the smallest unit with which I can use to measure the execution time of a C++ or C program? I have a program here that does it in milliseconds, but I was wondering if there is a smaller time unit. Is here a way I can measure time in processor ticks?
Here is such a program using larger time units
Code:
#include <stdio.h>
#include <sys/times.h>
int main(){
long i, j, k, T1, T2;
double a = 0.0, b = 0.0, c = 0.0;
struct tms start_time, stop_time;
k = 1000;
T1 = times(&start_time);
for(i=0;i<k;i++){
for(j=0;j<k;j++){
a += 1.0/c;
b = pow(0.22,2.5);
b = pow(0.22,2.5);
c += b;
}
}
T2 = times(&stop_time);
printf ("Execute Time for Loop: \n");
printf("%.3f seconds\n", (double)(stop_time.tms_utime-start_time.tms_utime)/1000.0f );
return 0;
}