"Karthigan Srinivasan" <ka*******@eart hlink.netwrote in message
news:op.t74o4kv wpinhaa@karthig an-desktop...
Is there an equivant method of
'time ./a.out'
in Windows to measure execution time for a program?
I put together the C program below which vaguely works, but you might get
ideas on how to do it properly. (I've never used command parameters in C
before).
--
Bart
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main(int n,char **cmds)
{char cmdstring[260];
int t;
int i,m;
char **p;
if (n<=1)
{if (n==1) printf("Usage: %s filename\n",*cm ds);
return EXIT_FAILURE;
};
++cmds; /* first param of interest, should be exe name */
/* must check all params combined fit into cmdstring (you can ignore this if
not posting your code!) */
m=0;
p=cmds;
for (i=2; i<=n; ++i) m+=(strlen(*p++ )+1);
if (m>sizeof(cmdst ring)) return EXIT_FAILURE;
/* All the trouble the system went to to separate the params, now we need to
join them all together again with spaces between */
/* Hint: if you can use Winmain() instead, the params are already joined up
*/
strcpy(cmdstrin g,*cmds);
for (i=3; i<=n; ++i)
{strcat(cmdstri ng," ");
strcat(cmdstrin g,*(++cmds));
};
printf("Executi ng %s ...\n",cmdstrin g);
t=clock();
system(cmdstrin g);
t=clock()-t;
printf("Executi on time: %d msec",t);
return EXIT_SUCCESS;
}