Jump to content

Recommended Posts

Posted

I have been searching Help and the forums but can't find exactly what I am looking for. I'm using AutoIT to execute a task and I want to capture the start time of the task, the end time, and the amount of time it took (down to a hundredth of a second). I want the results in the mm:ss:ms format.

I tried using TimerInit and TimerDiff which gives me the amount of time in milliseconds the task took, and I found a way to convert it to the format I want but it is a bit bulky. 

$time1 = TimerInit()
Run ("Notepad.exe")
sleep(1200)
WinWaitActive("Untitled - Notepad")
$timet = TimerDiff($time1)
$time2 = $time1 + $timet
$hour = Floor($time1 / 3600000)
$remanH = Mod($time1, 3600000)
$min = Floor($remanH / 60000)
$remanM = Mod($remanH, 60000)
$sec = Floor($remanM / 1000)
$remanS = Mod($remanM, 1000)
$msec = Floor($remanS)
$Task1a = $min & ":" & $sec & ":" & $msec
$hour = Floor($time2 / 3600000)
$remanH = Mod($time2, 3600000)
$min = Floor($remanH / 60000)
$remanM = Mod($remanH, 60000)
$sec = Floor($remanM / 1000)
$remanS = Mod($remanM, 1000)
$msec = Floor($remanS)
$Task1b = $min & ":" & $sec & ":" & $msec
$hour = Floor($timet / 3600000)
$remanH = Mod($timet, 3600000)
$min = Floor($remanH / 60000)
$remanM = Mod($remanH, 60000)
$sec = Floor($remanM / 1000)
$remanS = Mod($remanM, 1000)
$msec = Floor($remanS)
$Task1c = $min & ":" & $sec & ":" & $msec

I also tried capturing the start and end times using code below when the task begins and ends but haven't figured out how to do a calculation between the start and end times to get the actual time the task took:

$task1a = (@Hour & ':' & @Min & ':' & @Sec & ':' & @MSec)

Either way I would like to drop the thousandth millisecond and just have the 2 digits but not sure how to do that.

Can anyone offer a suggestion on a better to collect my times?

Posted

OK. I was using it as my start time since I want start time, end time, and the difference between the two. What would you suggest I use instead?

Posted

Thanks but those don't do what I want (as far as I can tell). The examples just produce the time difference which is only part of what I want.

Posted

I already included the pertinent parts of my efforts in my original post that I have tried as I test this out. I will include all of what I have tried so far but there isn't much more than I already shared.

One attempt:

$task1a = (@Hour & ':' & @Min & ':' & @Sec & ':' & @MSec)
Run ("Notepad.exe")
WinWaitActive("Untitled - Notepad")
sleep(1000)
$task1b = (@Hour & ':' & @Min & ':' & @Sec & ':' & @MSec)
$task1c = $task1a - $task1b
MsgBox(0, "Time start", "Start " & $task1a & " Stop " & $task1b & " time " & $task1c)
WinClose("Untitled - Notepad")

and then this:

$time1 = TimerInit() ; Begin the timer and store the handle in a variable.
Run ("Notepad.exe")
sleep(1200)
WinWaitActive("Untitled - Notepad")
$timet = TimerDiff($time1) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff.
$time2 = $time1 + $timet
$hour = Floor($time1 / 3600000)
$remanH = Mod($time1, 3600000)
$min = Floor($remanH / 60000)
$remanM = Mod($remanH, 60000)
$sec = Floor($remanM / 1000)
$remanS = Mod($remanM, 1000)
$msec = Floor($remanS)
$Task1a = $min & ":" & $sec & ":" & $msec
$hour = Floor($time2 / 3600000)
$remanH = Mod($time2, 3600000)
$min = Floor($remanH / 60000)
$remanM = Mod($remanH, 60000)
$sec = Floor($remanM / 1000)
$remanS = Mod($remanM, 1000)
$msec = Floor($remanS)
$Task1b = $min & ":" & $sec & ":" & $msec
$hour = Floor($timet / 3600000)
$remanH = Mod($timet, 3600000)
$min = Floor($remanH / 60000)
$remanM = Mod($remanH, 60000)
$sec = Floor($remanM / 1000)
$remanS = Mod($remanM, 1000)
$msec = Floor($remanS)
$Task1c = $min & ":" & $sec & ":" & $msec
MsgBox($MB_SYSTEMMODAL, "Time Difference", "start " & $Task1a & " end " & $Task1b & " diff " & $Task1c)
WinClose("Untitled - Notepad")

 

Posted

here :

Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
;do something here
; Local $iTime = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit.
Local $iTime = 4657891 ; for testing purpose here
ConsoleWrite("Time in ms " & $iTime & @CRLF)
$iTime = Int($iTime/1000) ; make it in secs
Local $hour = Floor($iTime / 3600)
ConsoleWrite("Number of hours = " & $hour & @CRLF)
$iTime -= $hour * 3600
Local $min = Floor($iTime / 60)
ConsoleWrite("Number of mins = " & $min & @CRLF)
Local $sec = Mod($iTime, 60)
ConsoleWrite("Number of secs = " & $sec & @CRLF)

 

  • Developers
Posted

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Nine, thanks for the response. Your code gives me the length of time my task takes but I also want to capture the start and end times. You said using the value of TimerInit as my start time isn't a good idea but I'm not sure how else to get it. Does the below look like a bad idea?

Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
ConsoleWrite("Start Time in ms " & $hTimer & @CRLF) ; Start time
sleep(900)
Local $iTime = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit.
$eTime = $hTimer + $iTime ; Add TimerInit TimerDiff results to generate End time.
;Local $iTime = 4657891 ; for testing purpose here
ConsoleWrite("Time in ms " & $iTime & @CRLF)
ConsoleWrite("End Time in ms " & $eTime & @CRLF)

 

Posted

Ultimately in min:sec:msec (00:00:0) but I only need the tenths of seconds (the first digit of msec). If I can only capture it in milliseconds then I can convert it to min:sec:msec. 

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
  • Recently Browsing   0 members

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