P
pedro.ballester
Hi everyone,
I am struggling with the following problem. I would like to measure the
wall clock time required to run a section of the code with a precision
of milliseconds. The attached code does the job on Windows Xp. However,
the code is not portable, as it fails to compile on Linux Red Hat. This
is the command and the errors:
# gcc -c time_loop.c
time_loop.c: In function 'main':
time_loop.c:34: error: storage size of 'tstruct1' isn't known
time_loop.c:34: error: storage size of 'tstruct2' isn't known
time_loop.c:26: warning: return type of 'main' is not 'int'
I will be grateful if anyone could tell know how to fix this problem so
that I can use the same code both on WinXp and Linux. In case it is not
possible, it will be very helpful to have alternative, preferably
concise, code that works on Linux.
Thanks in advance,
Pedro
Ps: and this is time_loop.c
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/timeb.h>
/* GLOBAL PARAMETERS DECLARATION */
#define NM 25000000
/* MAIN ROUTINE */
void main(void)
{
int i;
long idb; /* with "register", it seems to take longer! */
/* register long idb; */
double tms1, tms2, telapsed;
float diff[12];
float vec_a[12]={6., 3., 4., 3., 7., 2., 1., 3., 8., 4., 9., 3.};
float vec_b[12]={3., 7., 2., 1., 3., 8., 4., 9., 6., 3., 4., 3.};
struct __timeb64 tstruct1, tstruct2;
/* Starting time */
_ftime64( &tstruct1 );
tms1=(double)tstruct1.time+((double)tstruct1.millitm/1000.0);
for(idb=0; idb < NM; idb++)
{
for(i=0; i < 12; i++) diff=vec_a-vec_a;
}
/* Finishing time */
_ftime64( &tstruct2 );
tms2=(double)tstruct2.time+((double)tstruct2.millitm/1000.0);
telapsed=tms2-tms1;
printf("It took:\t%lf seconds to calculate diff %d times\n",
telapsed, NM );
}
I am struggling with the following problem. I would like to measure the
wall clock time required to run a section of the code with a precision
of milliseconds. The attached code does the job on Windows Xp. However,
the code is not portable, as it fails to compile on Linux Red Hat. This
is the command and the errors:
# gcc -c time_loop.c
time_loop.c: In function 'main':
time_loop.c:34: error: storage size of 'tstruct1' isn't known
time_loop.c:34: error: storage size of 'tstruct2' isn't known
time_loop.c:26: warning: return type of 'main' is not 'int'
I will be grateful if anyone could tell know how to fix this problem so
that I can use the same code both on WinXp and Linux. In case it is not
possible, it will be very helpful to have alternative, preferably
concise, code that works on Linux.
Thanks in advance,
Pedro
Ps: and this is time_loop.c
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/timeb.h>
/* GLOBAL PARAMETERS DECLARATION */
#define NM 25000000
/* MAIN ROUTINE */
void main(void)
{
int i;
long idb; /* with "register", it seems to take longer! */
/* register long idb; */
double tms1, tms2, telapsed;
float diff[12];
float vec_a[12]={6., 3., 4., 3., 7., 2., 1., 3., 8., 4., 9., 3.};
float vec_b[12]={3., 7., 2., 1., 3., 8., 4., 9., 6., 3., 4., 3.};
struct __timeb64 tstruct1, tstruct2;
/* Starting time */
_ftime64( &tstruct1 );
tms1=(double)tstruct1.time+((double)tstruct1.millitm/1000.0);
for(idb=0; idb < NM; idb++)
{
for(i=0; i < 12; i++) diff=vec_a-vec_a;
}
/* Finishing time */
_ftime64( &tstruct2 );
tms2=(double)tstruct2.time+((double)tstruct2.millitm/1000.0);
telapsed=tms2-tms1;
printf("It took:\t%lf seconds to calculate diff %d times\n",
telapsed, NM );
}