You can also try the following coding that I have made for setting the timings in C program. Here is the coding for that :
Code:
#include<stdio.h>
#include<sys/time.h>
#include<stdlib.h>
#include<sys/resource.h>
double getcputime();
int main(void)
{
int i, n, a;
double t;
n = 15;
printf("The 5-times Table\n");
for(i=1;i<n;i++)
{
a = (i * 5);
printf("%d\t%d\n", i, a);
}
printf("\n");
t = getcputime();
printf("The total time taken by the system is: %d (in decimal format)\n", t);
return 0;
}
double getcputime(void)
{
double t;
struct timeval tim;
struct rusage ru;
getrusage(RUSAGE_SELF, &ru);
tim=ru.ru_stime;
t=(double)tim.tv_sec * 1000000.0 + (double)tim.tv_usec;
return t;
}
Bookmarks