tags:

views:

9508

answers:

7

Can this be done with standard means?

+7  A: 

Not quite as elegant as some of the functionality in unix, but create a cmd file which looks like:

@echo off
time < nul
yourexecutable.exe > c:\temp\output.txt
time < nul

That will display the start and stop times like so:

The current time is: 10:31:57.92
Enter the new time: 
The current time is: 10:32:05.94
Enter the new time:
JohnW
Assuming you don't need portability across different languages you can also put a findstr "current" or something like that after the "time < nul" (nice usage of nul by the way; I've always used echo.|time, but that doesn't look as elegant :)). And use "for" to extract only the time, not the text.
Joey
+3  A: 

If you have a command window open and call the commands manually, you can display a timestamp on each prompt, e.g.

prompt $d $t $_$P$G

gives you something like

23.03.2009 15:45:50,77

C:\>

if you have a small batch script that executes your commands, have an empty line before each command, e.g.

(empty line)

myCommand.exe

(next empty line)

myCommand2.exe

you can calculate the execution time for each command by the time info in the prompt. The best would probably be to pipe the output to a textfile for further analysis:

MyBatchFile.bat >output.txt
Treb
+17  A: 

The Windows Server 2003 Resource Kit contains timeit.exe that displays detailed execution stats. Here is an example, timing the command "timeit -?":

C:\>timeit timeit -?
Invalid switch -?
Usage: TIMEIT [-f filename] [-a] [-c] [-i] [-d] [-s] [-t] [-k keyname | -r keyname] [-m mask] [commandline...]
where:        -f specifies the name of the database file where TIMEIT
                 keeps a history of previous timings.  Default is .\timeit.dat
              -k specifies the keyname to use for this timing run
              -r specifies the keyname to remove from the database.  If
                 keyname is followed by a comma and a number then it will
                 remove the slowest (positive number) or fastest (negative)
                 times for that keyname.
              -a specifies that timeit should display average of all timings
                 for the specified key.
              -i specifies to ignore non-zero return codes from program
              -d specifies to show detail for average
              -s specifies to suppress system wide counters
              -t specifies to tabular output
              -c specifies to force a resort of the data base
              -m specifies the processor affinity mask

Version Number:   Windows NT 5.2 (Build 3790)
Exit Time:        7:38 am, Wednesday, April 15 2009
Elapsed Time:     0:00:00.000
Process Time:     0:00:00.015
System Calls:     731
Context Switches: 299
Page Faults:      515
Bytes Read:       0
Bytes Written:    0
Bytes Other:      298

You can get TimeIt in the Windows 2003 Resource Kit. Download it here.

Thanks, that's what i need :)
Kuroki Kaze
This kit has issues with windows 2008 64bit and does not work on 2008 R2
Artem
I don't need it to work in Win 2008 :)
Kuroki Kaze
A: 
  1. In the directory where your program is, type notepad mytimer.bat, click yes to create a new file.

  2. Paste the code below, replacing YourApp.exe with your program, then save.

@echo off

date /t

time /t

YourApp.exe

date /t

time /t

  1. Type mytimer.bat in the command line then press Enter.
time /t only gives you time in HH:MM. To time an executable, you usually needs more accuracy... Is it anything you can setup to get down to fractions of a second? I tested the sollution from JohnW (time < nul), and that actually gives the time down to 1/100s: HH:MM:SS.XX
awe
+2  A: 

I use a freeware called "GS Timer".

Just make a batch file like this:

timer
yourapp.exe
timer /s

If you need a set of times, just pipe the output of timer /s into a .txt file.

You can get it here: GS Timer at SoftPedia

pepoluan
+3  A: 

Hehe, the most simple solution might be this:

echo %time% YourApp.exe echo %time%

This works on every Windows out of the box.

+1  A: 

The one-liner I use in Win2008 R2 is:

cmd /v:on /c "echo !TIME! & mycommand & echo !TIME!"

So long as mycommand doesn't require quotes (which screws with cmd's quote processing). The /v:on is to allow for the two different TIME values to be evaluated independently rather than once at the execution of the command.

Nathan Herring