473,238 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

Time ./a.out equivalent in Windows

Is there an equivant method of

'time ./a.out'

in Windows to measure execution time for a program?

Best Regards,
Karthigan.
Mar 16 '08 #1
17 4182
Karthigan Srinivasan wrote:
Is there an equivant method of

'time ./a.out'

in Windows to measure execution time for a program?

Best Regards,
Karthigan.
Download the package available at the following link:

<http://unxutils.sourceforge.net/>

Mar 16 '08 #2
"Karthigan Srinivasan" <ka*******@earthlink.netwrites:
Is there an equivant method of

'time ./a.out'

in Windows to measure execution time for a program?
We don't know. Well, some people here might happen to know, but this
isn't the place to ask, since your question really isn't about the C
programming language.

Try one of the comp.os.ms-windows.* or microsoft.* newsgroups.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 16 '08 #3
"Karthigan Srinivasan" <ka*******@earthlink.netwrote in message
news:op.t74o4kvwpinhaa@karthigan-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",*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;
}

Mar 16 '08 #4
Bartc wrote:

<snip>

I think you should divide the difference by CLOCKS_PER_SEC to get the
result in seconds. As such your program's result is always zero. This
is because you are strong a return value of type clock_t into an int.
Use a clock_t variable.

Also you could use malloc for concatenating the command arguments to
deal with large number of/long strings.

Mar 16 '08 #5
Bartc wrote:

<snip>

Since your program is paused by the operating system when the command
given to *system* is executing, both the return values from clock will
be the same, and thus the difference will always be zero.

You need to use functions beyond the C standard like POSIX *times*
function in sys/times.h to do this properly.

Mar 16 '08 #6
On Mar 16, 3:41*pm, "Bartc" <b...@freeuk.comwrote:
t=clock();

system(cmdstring);

t=clock()-t;

printf("Execution time: %d msec",t);
This output lies to the user if CLOCKS_PER_SEC isn't 1000.
Mar 16 '08 #7

"santosh" <sa*********@gmail.comwrote in message
news:fr**********@registered.motzarella.org...
Bartc wrote:

<snip>

Since your program is paused by the operating system when the command
given to *system* is executing, both the return values from clock will
be the same, and thus the difference will always be zero.
That's a good point. clock() should give the execution time of the program
doing the timing.

Nevertheless, it seemed to work! Or at least gave sensible results.

Maybe something to with Windows, and the OP wanted this on Windows.

--
Bart
Mar 16 '08 #8
santosh wrote:

<snip>

Well it is horribly broken in the sense that it will collapse all it's
arguments without preserving a space between them. A quick workaround
is to enclose all the arguments to the program inside a pair of double
quotes. Fixing it is left to the OP. :-)

Mar 17 '08 #9

"santosh" <sa*********@gmail.comwrote in message
news:fr**********@registered.motzarella.org...
Bartc wrote:
>>
"santosh" <sa*********@gmail.comwrote in message
news:fr**********@registered.motzarella.org...
>>Bartc wrote:

<snip>

Since your program is paused by the operating system when the command
given to *system* is executing, both the return values from clock
will be the same, and thus the difference will always be zero.

That's a good point. clock() should give the execution time of the
program doing the timing.

Nevertheless, it seemed to work! Or at least gave sensible results.

Maybe something to with Windows, and the OP wanted this on Windows.

Here is a more robust version of 'time'. Still not as good as the UNIX
version of course. This code is NOT standard C; it depends on
*gettimeofday* , which is specific to POSIX systems.

#include <stdio.h>
....
gettimeofday(&start, NULL);
....

Yes, that's pretty comprehensive, compared to my poor effort.

I see that you're measuring elapsed time, rather than execution time, which
I suppose is a good alternative (I sometimes just use my watch).

--
Bart
Mar 17 '08 #10
Bartc wrote:
>
"santosh" <sa*********@gmail.comwrote in message
news:fr**********@registered.motzarella.org...
>Bartc wrote:

<snip>

Since your program is paused by the operating system when the command
given to *system* is executing, both the return values from clock
will be the same, and thus the difference will always be zero.

That's a good point. clock() should give the execution time of the
program doing the timing.
It does. Trouble is, the execution of our program is suspended when the
argument to system is running. As far as clock is concerned, no time
has elapsed between the call to system and it's return.

To stick to pure standard C we will have to use the time function, whose
resolution is usually isn't sufficient for use in a "time" command.

<snip>

Mar 17 '08 #11
"Bartc" <bc@freeuk.comwrites:
"Karthigan Srinivasan" <ka*******@earthlink.netwrote in message
news:op.t74o4kvwpinhaa@karthigan-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).
[snip]

The Unix/Linux "time" command cannot be implemented in purely standard
C. There are various versions of the "time" command, some of them
built into various shells. It typically reports the wall-clock time,
the user-mode CPU time, the system-mode CPU time, and the percentage
of time spent in CPU time; it may also report various I/O statistics.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 17 '08 #12
In article <87************@kvetch.smov.org>,
Keith Thompson <ks***@mib.orgwrote:
>"Bartc" <bc@freeuk.comwrites:
>"Karthigan Srinivasan" <ka*******@earthlink.netwrote in message
news:op.t74o4kvwpinhaa@karthigan-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).
[snip]

The Unix/Linux "time" command cannot be implemented in purely standard C.
True, given that the C standard doesn't admit of any kind of
multi-processing, so the whole concept is moot.

You, of all people, ought to know that.

Mar 17 '08 #13
In article <73**********************************@s8g2000prg.g ooglegroups.com>,
Kaz Kylheku <kk******@gmail.comwrote:
....
>GetTickCount ...
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
>alone the best one available on Windows. The Windows API provides
GetThreadTimes ...
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
>and GetProcessTimes ...
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
>to launch it with CreateProcess...
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
>WaitForSingleObject ...
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
>status using GetExitCodeEx...
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
>collect the times using GetProcessTimes ...
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.
>and then close both the process and thread handle(s).
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

Well done. Your post is completely OT.

Mar 17 '08 #14
Karthigan Srinivasan wrote:
Is there an equivant method of

'time ./a.out'

in Windows to measure execution time for a program?

Best Regards,
Karthigan.
#include <windows.h>
#include <stdio.h>
int main(int argc,char *argv[])
{
int ms;

if (argc < 2) {
printf(
"Usage: %s \"command\" (enclosed in double quotes)\n",
argv[0]);
return -1;
}
ms = GetTickCount();
system(argv[1]);
ms = GetTickCount() - ms;
printf("\n'%s'\nexecuted in %d ms\n",argv[1],ms);
return 0;
}


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Mar 17 '08 #15
On 17 Mar 2008 at 2:48, Kenny McCormack wrote:
In article <87************@kvetch.smov.org>,
Keith Thompson <ks***@mib.orgwrote:
>>The Unix/Linux "time" command cannot be implemented in purely standard C.

True, given that the C standard doesn't admit of any kind of
multi-processing, so the whole concept is moot.

You, of all people, ought to know that.
But you of all people ought to know that the usual rules of topicality
don't apply to The Clique, who are free to discuss novels, electric
wiring, American politics and anything else they like.

That's the Principle of Hypocrisy that everyone around here holds dear.

Mar 17 '08 #16

"jacob navia" <ja***@nospam.comwrote in message
news:fr**********@aioe.org...
Karthigan Srinivasan wrote:
>Is there an equivant method of

'time ./a.out'
in Windows to measure execution time for a program?
#include <windows.h>
....
"Usage: %s \"command\" (enclosed in double quotes)\n", argv[0]);
If you're going to go this far, you might as well do this and get rid of the
double quotes:

#include <stdio.h>
#include <windows.h>

int STDCALL WinMain(HINSTANCE x,HINSTANCE y,char* cmdline,int z)
{int ms;

if (*cmdline==0) return EXIT_FAILURE;

ms = GetTickCount();
system(cmdline);
ms = GetTickCount() - ms;
printf("\n'%s'\nexecuted in %d ms\n",cmdline,ms);
return 0;
}
(Clearly, non-portable outside of Windows. And quite a non-standard way of
defining main().)

--
Bart
Mar 17 '08 #17
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>On 17 Mar 2008 at 2:48, Kenny McCormack wrote:
>In article <87************@kvetch.smov.org>,
Keith Thompson <ks***@mib.orgwrote:
>>>The Unix/Linux "time" command cannot be implemented in purely standard C.

True, given that the C standard doesn't admit of any kind of
multi-processing, so the whole concept is moot.

You, of all people, ought to know that.

But you of all people ought to know that the usual rules of topicality
don't apply to The Clique, who are free to discuss novels, electric
wiring, American politics and anything else they like.
So true. So true.
>That's the Principle of Hypocrisy that everyone around here holds dear.
Indeed. What was I thinking???

Mar 17 '08 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: carbon_dragon | last post by:
Ok, so here is the problem. I'm working on a headless server program implemented as a .NET C# Console project. There is a UPS mounted to this server (though not a windows compliant UPS). I can only...
3
by: leo_junquera | last post by:
I am trying to use windows authentication on an intranet to call a web service. When I make my first call to the service after connecting from a client app using: ws.Url = ServiceUrl;...
2
by: anand.ba | last post by:
Hi all I need to find equivalent windows libraries for the following unix ones. #include <sys/prctl.h> #include <sys/ioctl.h> #include <unistd.h>
9
by: aaronluna | last post by:
Hi All, I was wondering if it is possible to easily convert an asp.net user control (.ascx) into an equivalent windows app. I plan on simply duplicating the user control in a c# windows app...
4
by: chaitanya.sharma | last post by:
Hi, I am looking for a function that is similar to rl_bind_key (linux) for windows. Is there any such function. I am creating a small shell and want to detect if a particular key is pressed on...
0
by: Will | last post by:
Can anyone recommend how I would build a tag cloud on a Windows Form? Is there a control I can use instead of the web based literal control?
1
by: Pankajmani das | last post by:
I have developed a program which is need to run automatically when windows/computer start. I have kept my exe file in startup and task folder manually and it work also. Please let me know the code...
0
by: mukeshk | last post by:
hi, I want to know the project directory path for my windows application. I have a file(say Myfile.txt) which is included in the project as Solution Dir -Project Dir --project files --Myfile.txt...
0
by: vijayat23 | last post by:
In my application, there is a situation, I have to re size the controls during runtime. How can i achieve that. Thanks in advance
8
by: Theo v. Werkhoven | last post by:
hi, In this code I read out an instrument during a user determined period, and save the relative time of the sample (since the start of the test) and the readback value in a csv file. #v+...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.