Re: Time ./a.out equivalent in Windows



"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;
}



.



Relevant Pages

  • Re: LogonUser()
    ... // This sample can be run only on Windows XP. ... String lpszPassword, ... int dwLogonType, int dwLogonProvider, ref IntPtr phToken); ... private unsafe static extern int FormatMessage(int dwFlags, ref IntPtr ...
    (microsoft.public.dotnet.security)
  • Re: WS_CAPTION bug (only on Vista?)
    ... Of course, it still leaves the question of what 'parent' and 'child' are, and why ... anyone would consider an 'int' as a valid type for a boolean value... ... I have a couple Vista systems and thought I'd give it a shot, ... specification of what windows are being passed in. ...
    (microsoft.public.vc.mfc)
  • Re: bringing Pocket Internet Explorer (PIE) to foreground
    ... Peter Foot ... the PIE window did not come to the foreground on the ASUS ... >> Windows Embedded MVP ... >>> public static extern int FindWindow (string lpClassName, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: input/output sound level calibration
    ... Inialisation et configuration mixer de la carte son ... sound_mix_apparatus (void) ... unsigned int nver; ... standard Windows pop-up mixer since it doesn't show the ...
    (comp.sys.ibm.pc.soundcard.tech)
  • Re: W2k/XP hangs with "TAB BS BS" on console
    ... >> console compiler) was executed: ... Now in this function we can see if we disassemble that 'int 2Eh' is called, ... _KiSystemService copies the parameters from the Ring 3 stack which EDX ... NT has this problem in all service packs, Windows 2000 has it and XP seems ...
    (NT-Bugtraq)