Jump to content

Timer


gcriaco
 Share

Recommended Posts

Purpose: launch a command and calculates duration

Usage: timer command (ie timer copy *.au3 \backup)

;===================================================================================================

================================================
;
; Program Name:  Timer()
; Description:    Calculates the elapsed time between start-end of a monitored command
; Parameter(s):  Command to evluate from command line (ie: copy *.au3 c:\temp)
; Requirement(s):   None
; Return Value(s):  Elapsed Time
; Author(s):        Giuseppe Criaco <gcriaco@quipo.it>
;
;===================================================================================================

================================================
#include <Date.au3>

Local $Hour, $Mins, $Secs

If $CmdLine[0] = 0 Then
    #Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
    MsgBox(16,"test","Command-line parameter not supplied")
    #EndRegion --- CodeWizard generated code End ---
    Exit
EndIf

$StartingTime = _NowTime(5)
$Timer = TimerInit()

$val = RunWait(@ComSpec & " /c " & $CmdLineRaw,"",@SW_HIDE)

$EndingTime = _NowTime(5)

_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs )
$ElapsedTime = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)

#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info
MsgBox(64,"Time Calculator","Starting Time: " & $StartingTime & @CRLF & "Ending Time  : " & $EndingTime & @CRLF & @CRLF & "Elapsed Time:  " & $ElapsedTime)
#EndRegion --- CodeWizard generated code End ---
Edited by gcriaco
Link to comment
Share on other sites

Thanks, I was searching for this script! :lmao:

Can you please set your code into the

tag?

If I run beta I've these error:

Command-line parameter not supplied

Compile the script and launch at the Dos prompt:

timer command , where command is anything you want to monitor.

Example: timer xcopy c:\in\*.* d:\out

Trick: copy timer.exe to a directory pointed by the %path% variable (ie c:\windows\system32", so that is always available at the Dos prompt

Edited by gcriaco
Link to comment
Share on other sites

I've used this several times. like it and have some suggestions:

  • On the message box that gives the results, also display the name of the command that was timed.
  • Add an option to write the command name and the results to a single line in a 'CSV' or 'TSV' file. The user timing more than a couple of trials won't have write them down and then key them into a spreadsheet.
  • Include an option to run, not runwait several commands in parallel (this would be good for things that happen mostly in memory). Use arrays to keep track of the times and commands.
  • Include an option to run and/or runwait commands from a file. This with the first suggestion would allow a tester to setup a whole series of commands to be timed or the same command timed with different circumstances/parameters.
  • In the case of #4 it would be good to allow the user to include a comment with each command to help identify each trial in the output file.
  • As long as your granularity is one second you could include an option to use the ProcessExists function to capture the actual processing time of a command excluding the load time.
  • The 2 suggestions concerning running commands in parallel could also be used to stress test a computer.
I realize that it is easier to suggest things than to do them. At the same time you've got a good basic tool that could have much more usability. I'm happy to answer questions concerning any of the suggestions.

Gene

Purpose: launch a command and calculates duration

Usage: timer command (ie timer copy *.au3 \backup)

;===================================================================================================

================================================
;
; Program Name:  Timer()
; Description:    Calculates the elapsed time between start-end of a monitored command
; Parameter(s):  Command to evluate from command line (ie: copy *.au3 c:\temp)
; Requirement(s):   None
; Return Value(s):  Elapsed Time
; Author(s):        Giuseppe Criaco <gcriaco@quipo.it>
;
;===================================================================================================

================================================
#include <Date.au3>

Local $Hour, $Mins, $Secs

If $CmdLine[0] = 0 Then
    #Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
    MsgBox(16,"test","Command-line parameter not supplied")
    #EndRegion --- CodeWizard generated code End ---
    Exit
EndIf

$StartingTime = _NowTime(5)
$Timer = TimerInit()

$val = RunWait(@ComSpec & " /c " & $CmdLineRaw,"",@SW_HIDE)

$EndingTime = _NowTime(5)

_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs )
$ElapsedTime = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)

#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info
MsgBox(64,"Time Calculator","Starting Time: " & $StartingTime & @CRLF & "Ending Time  : " & $EndingTime & @CRLF & @CRLF & "Elapsed Time:  " & $ElapsedTime)
#EndRegion --- CodeWizard generated code End ---

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

I've used this several times. like it and have some suggestions:

  • On the message box that gives the results, also display the name of the command that was timed.

  • Add an option to write the command name and the results to a single line in a 'CSV' or 'TSV' file. The user timing more than a couple of trials won't have write them down and then key them into a spreadsheet.

  • Include an option to run, not runwait several commands in parallel (this would be good for things that happen mostly in memory). Use arrays to keep track of the times and commands.

  • Include an option to run and/or runwait commands from a file. This with the first suggestion would allow a tester to setup a whole series of commands to be timed or the same command timed with different circumstances/parameters.

  • In the case of #4 it would be good to allow the user to include a comment with each command to help identify each trial in the output file.

  • As long as your granularity is one second you could include an option to use the ProcessExists function to capture the actual processing time of a command excluding the load time.

  • The 2 suggestions concerning running commands in parallel could also be used to stress test a computer.
I realize that it is easier to suggest things than to do them. At the same time you've got a good basic tool that could have much more usability. I'm happy to answer questions concerning any of the suggestions.

Gene

Thanks for suggestions.

I'll work on it ASAP.

Link to comment
Share on other sites

timer ver 1.1 released

Description:

Calculates the elapsed time since a given command started

Usage: timer [options] command/filename

Options:

-f filename text file with commands

Text file format:

- one command per row

- blank lines will be ignored

- comments (rows prefixed with ";") will be ignored

Examples: timer copy *.au3 c:\Backup

timer -f c:\Tmp\CmdList.txt

The output is appended to the file Timer.log

ChangeLog:

1.0 - 1/18/2006

- Initial release

1.1 - 1/20/2006

- Removed: Output Message box

- Added: Resource Info (version, description,...) in the exe file

- Added: The command name and the results are written in a log file

- Added: The command option "-f" to monitor commands from a file

Likely i'll continue to improve the script (see previous suggestions).

Edited by gcriaco
Link to comment
Share on other sites

This looks great, I'll probably try it out later today.

Gene

Edited spelling

timer ver 1.1 released

Description:

Calculates the elapsed time since a given command started

Usage: timer [options] command/filename

Options:

-f filename text file with commands

Text file format:

- one command per row

- blank lines will be ignored

- comments (rows prefixed with ";") will be ignored

Examples: timer copy *.au3 c:\Backup

timer -f c:\Tmp\CmdList.txt

The output is appended to the file Timer.log

ChangeLog:

1.0 - 1/18/2006

- Initial release

1.1 - 1/20/2006

- Removed: Output Message box

- Added: Resource Info (version, description,...) in the exe file

- Added: The command name and the results are written in a log file

- Added: The command option "-f" to monitor commands from a file

Likely i'll continue to improve the script (see previous suggestions).

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...