Re: Time ./a.out equivalent in Windows
- From: "Bartc" <bc@xxxxxxxxxx>
- Date: Sun, 16 Mar 2008 22:41:22 GMT
"Karthigan Srinivasan" <karthigan@xxxxxxxxxxxxx> wrote in message
news:op.t74o4kvwpinhaa@xxxxxxxxxxxxxxxxxxxx
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",*cmds);
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(cmdstring)) 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(cmdstring,*cmds);
for (i=3; i<=n; ++i)
{strcat(cmdstring," ");
strcat(cmdstring,*(++cmds));
};
printf("Executing %s ...\n",cmdstring);
t=clock();
system(cmdstring);
t=clock()-t;
printf("Execution time: %d msec",t);
return EXIT_SUCCESS;
}
.
- Follow-Ups:
- Re: Time ./a.out equivalent in Windows
- From: Keith Thompson
- Re: Time ./a.out equivalent in Windows
- From: Kaz Kylheku
- Re: Time ./a.out equivalent in Windows
- From: santosh
- Re: Time ./a.out equivalent in Windows
- From: santosh
- Re: Time ./a.out equivalent in Windows
- References:
- Time ./a.out equivalent in Windows
- From: Karthigan Srinivasan
- Time ./a.out equivalent in Windows
- Prev by Date: Re: gcc: What's illegal about this ?
- Next by Date: Re: bunch of pedants
- Previous by thread: Re: Time ./a.out equivalent in Windows
- Next by thread: Re: Time ./a.out equivalent in Windows
- Index(es):
Relevant Pages
|