Hello everybody,
The program which I attach estimates the time taken to populate a matrix with its elements. Though this program does run if I compile it under Unix, it does not run if I
compile it in an ordinary compiller. My question is: When we use the time command in a C program do we always have to compile the program under Unix only and not ordinary
compilers? Is it possible to make the program compile in ordinary compilers? Which is the correct program, without errors for a windows compiler?
#include <stdio.h>
#include <sys/time.h> /* Necessary libraries for the time complexity */
#include <time.h>
#include <sys/resource.h>
double gettime(void);
int main (void)
{
int i,j;
int arr[200][200];
double time;
time = gettime();
for (i=0; i<199; i++)
{
for (j=0; j<199; j++)
{
arr[j]=10*i+j;
printf("%d\n", arr[j]);
}
}
printf("Time is %f\n", (gettime()-time)/100000.0);
system("PAUSE");
return 0;
}
double gettime(void) /* Function defiition, Code taken under agreement with Professor J.P. Fitch */
{
struct rusage r;
double tt;
getrusage(0, &r);
tt=1000.0*(double)(r.ru_utime.tv_sec)+(double)(r.ru_utime.tv_usec)/1000.0+
1000.0*(double)(r.ru_stime.tv_sec)+(double)(r.ru_stime.tv_usec)/1000.0;
return tt;
}
Regards
The program which I attach estimates the time taken to populate a matrix with its elements. Though this program does run if I compile it under Unix, it does not run if I
compile it in an ordinary compiller. My question is: When we use the time command in a C program do we always have to compile the program under Unix only and not ordinary
compilers? Is it possible to make the program compile in ordinary compilers? Which is the correct program, without errors for a windows compiler?
#include <stdio.h>
#include <sys/time.h> /* Necessary libraries for the time complexity */
#include <time.h>
#include <sys/resource.h>
double gettime(void);
int main (void)
{
int i,j;
int arr[200][200];
double time;
time = gettime();
for (i=0; i<199; i++)
{
for (j=0; j<199; j++)
{
arr[j]=10*i+j;
printf("%d\n", arr[j]);
}
}
printf("Time is %f\n", (gettime()-time)/100000.0);
system("PAUSE");
return 0;
}
double gettime(void) /* Function defiition, Code taken under agreement with Professor J.P. Fitch */
{
struct rusage r;
double tt;
getrusage(0, &r);
tt=1000.0*(double)(r.ru_utime.tv_sec)+(double)(r.ru_utime.tv_usec)/1000.0+
1000.0*(double)(r.ru_stime.tv_sec)+(double)(r.ru_stime.tv_usec)/1000.0;
return tt;
}
Regards