Sign in to follow this  
Followers 0
Anne

TimerInit & TimerDiff limits / max value

10 posts in this topic

Hi everyone.

I have a question and wasn't able to find any answer for this.

What is the maximum value/limit for TimerInit & TimerDiff.

I mean, If I use TimerInit() in my script, how long can it 'last'? How long will I be able to read it with TimerDiff()?

I realize that the result of TimerDiff isn't an Integer. It's a floating number and I am not sure what the maximum value is.

I would like my program to use $Time = TimerInit() today, and then I'll be able to use TimerDiff($Time) tomorrow or even the day after. Is this possible? and what happens if TimerDiff exceeds the maximum value (if there is any)?

Share this post


Link to post
Share on other sites



TimerDiff returns the elapsed time in milliseconds calculated from a previous call to TimerInit. I can't test at the moment but I'm sure the result is an integer.
Use IsInt or IsFloat to check if it is an integer or a floating number.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

If TimerInit uses the Kernel32.dll function QueryPerformanceCounter to calculate what values it gives, then it's probably about 68 years all the way up to 80,000 years according to this post I found. But a developer would need to answer this question as to how they obtain the values it uses.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

 

I would like my program to use $Time = TimerInit() today, and then I'll be able to use TimerDiff($Time) tomorrow or even the day after. Is this possible? and what happens if TimerDiff exceeds the maximum value (if there is any)?

Just give it a try and you know if it works by tomorrow.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

TimerDiff returns the elapsed time in milliseconds calculated from a previous call to TimerInit. I can't test at the moment but I'm sure the result is an integer.

Use IsInt or IsFloat to check if it is an integer or a floating number.

 

Well I know that it isn't an Integer. Because after 1 second has elapsed, the result of TimerDiff would be something like 1000.48243

Which is why I asked what the maximum value of a floating number would be.

 

If TimerInit uses the Kernel32.dll function QueryPerformanceCounter to calculate what values it gives, then it's probably about 68 years all the way up to 80,000 years according to this post I found. But a developer would need to answer this question as to how they obtain the values it uses.

 

Very good reply! Now, is it possible for a floating number to hold that value in milliseconds? I mean, that would be "2144448000000" milliseconds.

Just give it a try and you know if it works by tomorrow.

 

Yea I am already testing this, but I asked because what happens if I let it wait 2 days, 3 days, 1 week etc. It would take forever to get the answer by testing it.

Share this post


Link to post
Share on other sites

Anne,

TimerInit/Diff should generally only be used for measuring relatively small time periods. If you are looking to determine delays of "2 days, 3 days, 1 week etc" I would recommend using either DateDiff on suitable DTG strings or (if accuracy is not that necessary) the various date/time macros that you can find in this list. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Anne,

TimerInit/Diff should generally only be used for measuring relatively small time periods. If you are looking to determine delays of "2 days, 3 days, 1 week etc" I would recommend using either DateDiff on suitable DTG strings or (if accuracy is not that necessary) the various date/time macros that you can find in this list. :)

M23

 

I had actually considered this as a solution but after giving it some work I realized that I couldn't make it accurate enough.

Say I want the script to perform a certain task 75½ hours after it has been executed.

Or exactly 24 hours (+/- 1 min) after execution.

In practise, I will need it to measure anything from 5 mins to a few days, which is why I'd prefer TimerInit/TimerDiff. However, it could be possible to use both solutions along each other.

I guess I will just have to try working with the Timer functions untill I (maybe) hit a natural wall and then move on to DateDiff for some of the timing instead.

Share this post


Link to post
Share on other sites

Anne,

 

perform a certain task 75½ hours after it has been executed. Or exactly 24 hours (+/- 1 min) after execution

The macros are perfectly suitable for that. Just poll them at a suitable interval - say 1 hr intervals for 23 hours, then 1 min intervals until 23:59, and finally 1 sec intervals until you reach the correct moment. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Anne,

 

The macros are perfectly suitable for that. Just poll them at a suitable interval - say 1 hr intervals for 23 hours, then 1 min intervals until 23:59, and finally 1 sec intervals until you reach the correct moment. :)

M23

 

I must have been drunk since I did not think of this.

That's perfect thanks M23!

Share this post


Link to post
Share on other sites

Anne,

Glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • TheAutomator
      By TheAutomator
      Hi, simple question actually:
      How to disable the character limit for an edit control?
      Want unlimited-length (or as much as possible)
      I know the GUICtrlSetLimit() function but i want to disable the limit, not set one...
      Any ideas?
      I thought there was some sort of autoit constant for this or something but cant find what i'm looking for.
    • guinness
      By guinness
      This is for my C# fans out there who enjoy OOP. I have created a really rough draft (I mean it's super basic) of the Stopwatch Class in .NET, because I had the idea whilst travelling home and just thought it's neat to show a different paradigm to that of procedural programming.
       
      Enjoy.

      #include <WinAPISys.au3> Global Const $STOPWATCH_GUID = '804835D8-0DF4-11E4-A11F-29560707A45E', $STOPWATCH_TICKSPERMILLISECOND = 10000, $STOPWATCH_TICKSPERSECOND = $STOPWATCH_TICKSPERMILLISECOND * 1000 Global Enum $STOPWATCH_TIMER, $STOPWATCH_RUNNING, $STOPWATCH_ELAPSED, $STOPWATCH_ISHIGHRESOLUTION, $STOPWATCH_FREQUENCY, $STOPWATCH_TICKFREQUENCY, $STOPWATCH_ID, $STOPWATCH_MAX #Region Example Example() Func Example() Local $hStopWatch = Stopwatch() ConsoleWrite('IsRunning: ' & Stopwatch_IsRunning($hStopWatch) & @CRLF) ; Display running status. ConsoleWrite('Started' & @CRLF) Stopwatch_Start($hStopWatch) ; Start the stopwatch. ConsoleWrite('IsRunning: ' & Stopwatch_IsRunning($hStopWatch) & @CRLF) ; Display running status. Sleep(1000) ; Wait for 1 second. Stopwatch_Stop($hStopWatch) ; Stop the stopwatch. ConsoleWrite('Elapsed ms Time: ' & Stopwatch_ElapsedMilliseconds($hStopWatch) & @CRLF) ConsoleWrite('Stopped.' & @CRLF) ConsoleWrite('Waiting for 3 seconds whilst the stopwatch is stopped.' & @CRLF) Sleep(3000) ; Wait for 3 seconds. ConsoleWrite('Started' & @CRLF) Stopwatch_Start($hStopWatch) ; Start the stopwatch again. ConsoleWrite('Waiting for 2 seconds whilst the stopwatch is running' & @CRLF) Sleep(2000) ; Wait for 2 seconds. For $i = 1 To 10 ; The number of milliseconds is shown even when the stopwatch is running. ConsoleWrite('Elapsed ms Time: ' & Stopwatch_ElapsedMilliseconds($hStopWatch) & @CRLF) Sleep(250) Next Stopwatch_Stop($hStopWatch) ; Stop the stopwatch. ConsoleWrite('Elapsed ms Time: ' & Stopwatch_ElapsedMilliseconds($hStopWatch) & @CRLF) ; This should be about 5 seconds or so. ConsoleWrite('Stopped' & @CRLF) ConsoleWrite('IsRunning: ' & Stopwatch_IsRunning($hStopWatch) & @CRLF) ; Display running status. EndFunc ;==>Example #EndRegion Example ; Stopwatch Class: http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx Func Stopwatch() Local $aStopwatch[$STOPWATCH_MAX] $aStopwatch[$STOPWATCH_ID] = $STOPWATCH_GUID Stopwatch_Reset($aStopwatch) $aStopwatch[$STOPWATCH_FREQUENCY] = _WinAPI_QueryPerformanceFrequency() If $aStopwatch[$STOPWATCH_FREQUENCY] > 0 Then $aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] = True $aStopwatch[$STOPWATCH_TICKFREQUENCY] = $STOPWATCH_TICKSPERSECOND $aStopwatch[$STOPWATCH_TICKFREQUENCY] /= $aStopwatch[$STOPWATCH_FREQUENCY] Else $aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] = False $aStopwatch[$STOPWATCH_FREQUENCY] = $STOPWATCH_TICKSPERSECOND $aStopwatch[$STOPWATCH_TICKFREQUENCY] = 1 EndIf Return $aStopwatch EndFunc ;==>Stopwatch Func Stopwatch_ElapsedMilliseconds(ByRef $aStopwatch) Return (__Stopwatch_IsStopwatch($aStopwatch) ? __Stopwatch_GetElapsedDateTimeTicks($aStopwatch) / $STOPWATCH_TICKSPERMILLISECOND : 0) EndFunc ;==>Stopwatch_ElapsedMilliseconds Func Stopwatch_ElapsedTicks(ByRef $aStopwatch) Return (__Stopwatch_IsStopwatch($aStopwatch) ? __Stopwatch_GetElapsedDateTimeTicks($aStopwatch) : 0) EndFunc ;==>Stopwatch_ElapsedTicks Func Stopwatch_IsRunning(ByRef $aStopwatch) Return (__Stopwatch_IsStopwatch($aStopwatch) ? $aStopwatch[$STOPWATCH_RUNNING] : Null) EndFunc ;==>Stopwatch_IsRunning Func Stopwatch_Reset(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) Then $aStopwatch[$STOPWATCH_ELAPSED] = 0 $aStopwatch[$STOPWATCH_RUNNING] = False $aStopwatch[$STOPWATCH_TIMER] = 0 EndIf Return True EndFunc ;==>Stopwatch_Reset Func Stopwatch_Restart(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) Then Stopwatch_Reset($aStopwatch) Stopwatch_Start($aStopwatch) EndIf Return True EndFunc ;==>Stopwatch_Restart Func Stopwatch_Start(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) And Not $aStopwatch[$STOPWATCH_RUNNING] Then $aStopwatch[$STOPWATCH_RUNNING] = True $aStopwatch[$STOPWATCH_TIMER] = __Stopwatch_GetTimestamp($aStopwatch) EndIf Return True EndFunc ;==>Stopwatch_Start Func Stopwatch_StartNew() Local $aStopwatch = Stopwatch() Stopwatch_Start($aStopwatch) Return $aStopwatch EndFunc ;==>Stopwatch_StartNew Func Stopwatch_Stop(ByRef $aStopwatch) If __Stopwatch_IsStopwatch($aStopwatch) And $aStopwatch[$STOPWATCH_RUNNING] Then $aStopwatch[$STOPWATCH_ELAPSED] = __Stopwatch_GetRawElapsedTicks($aStopwatch) $aStopwatch[$STOPWATCH_RUNNING] = False EndIf Return True EndFunc ;==>Stopwatch_Stop Func __Stopwatch_GetElapsedDateTimeTicks(ByRef $aStopwatch) Return (__Stopwatch_GetRawElapsedTicks($aStopwatch) * ($aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] ? $aStopwatch[$STOPWATCH_TICKFREQUENCY] : $STOPWATCH_TICKSPERMILLISECOND)) EndFunc ;==>__Stopwatch_GetElapsedDateTimeTicks Func __Stopwatch_GetRawElapsedTicks(ByRef $aStopwatch) Local $iElapsedTime = $aStopwatch[$STOPWATCH_ELAPSED] If $aStopwatch[$STOPWATCH_RUNNING] Then If $aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] Then Local $iTimeStamp = __Stopwatch_GetTimestamp($aStopwatch) $iTimeStamp = $iTimeStamp - $aStopwatch[$STOPWATCH_TIMER] $iElapsedTime += $iTimeStamp Else $iElapsedTime += TimerDiff($aStopwatch[$STOPWATCH_TIMER]) EndIf EndIf Return $iElapsedTime EndFunc ;==>__Stopwatch_GetRawElapsedTicks Func __Stopwatch_GetTimestamp(ByRef $aStopwatch) Return ($aStopwatch[$STOPWATCH_ISHIGHRESOLUTION] ? _WinAPI_QueryPerformanceCounter() : TimerInit()) EndFunc ;==>__Stopwatch_GetTimestamp Func __Stopwatch_IsStopwatch(ByRef $aStopwatch) ; Internal function only. Return (UBound($aStopwatch) = $STOPWATCH_MAX And $aStopwatch[$STOPWATCH_ID] = $STOPWATCH_GUID) EndFunc ;==>__Stopwatch_IsStopwatch
    • Andreik
      By Andreik
      I use a DateTimePicker control and now I saw the minimum value for the year it's 1601. Know anyone how can be changed this limit?
    • Decipher
      By Decipher
      I took a script written by Beege, optimized the code, and removed the global variables. Its one function, reliable, and very easy to use or modify to your needs. I decided to post it because I found it very hard to find a reliable way to get the cpu percentage of a given process. I know that there are a few different methods but I deem WMI unreliable and everything I tried before optimizing this function was to slow i.e. freezing when other CPU intensive processes were active.
      When monitoring a potentially CPU intensive process, I found it necessary to increase the script's priority otherwise the script/system would freeze which is exactly what I was attempting to prevent!
      See Beege's updated post:
      #NoTrayIcon #include <WinAPI.au3> HotKeySet('{ESC}', '_Exit') Func _Exit() Exit EndFunc ;==>_Exit _LimitProcessCPU("MediaServer.exe", 10, 1, 5) Func _LimitProcessCPU($vProcess, $nLimit, $nInterval = 1, $nScriptPriority = 2) Local $nProcessCpu = -1, $nOverLimit = 0 While ProcessExists($vProcess) $nProcessCpu = _ProcessCPU($vProcess, $nScriptPriority) If $nProcessCpu > 50 Then $nOverLimit += 1 Else $nOverLimit = 0 EndIf If $nOverLimit > $nLimit Then $nOverLimit = 0 ProcessClose($vProcess) ; < - Replace this with what you need. EndIf Sleep($nInterval*1000) WEnd EndFunc Func _ProcessCPU($nPID = @AutoItPID, $nScriptPriority = 2) ; Realtime priority = 5 ; Original Author: Beege -> http://www.autoitscript.com/forum/user/8949-beege/ $nPID = ProcessExists($nPID) If Not $nPID Then Return SetError(1, 0, "") EndIf Local Const $tagFILETIME = "struct;dword Lo;dword Hi;endstruct", $nStructs = 7 Local Static $aStruct[$nStructs], $aPointer[$nStructs], $aStat[4], $hProcess = _WinAPI_OpenProcess(0x1F0FFF, 0, $nPID, True), $bFirstRun = True Local Enum $nIDLETIME, $nKERNELTIME, $nUSERTIME, $nPCreationTime, $nPExitTime, $nPKernelTime, $nPUserTime, _ $nProcStartKern = 0, $nProcStartUser, $nStartKernel, $nStartUser If $bFirstRun Then For $i = 0 To $nStructs - 1 Step 1 $aStruct[$i] = DllStructCreate($tagFILETIME) $aPointer[$i] = DllStructGetPtr($aStruct[$i]) Next EndIf DllCall('Kernel32.dll', "int", "GetSystemTimes", "ptr", $aPointer[$nIDLETIME], "ptr", $aPointer[$nKERNELTIME], "ptr", $aPointer[$nUSERTIME]) DllCall('Kernel32.dll', "int", "GetProcessTimes", "hwnd", $hProcess, "ptr", $aPointer[$nPCreationTime], "ptr", $aPointer[$nPExitTime], "ptr", _ $aPointer[$nPKernelTime], "ptr", $aPointer[$nPUserTime]) Local $aTemp[4] = [DllStructGetData($aStruct[$nPKernelTime], 1), DllStructGetData($aStruct[$nPUserTime], 1), DllStructGetData($aStruct[$nKERNELTIME], 1), _ DllStructGetData($aStruct[$nUSERTIME], 1)], $tProcess, $tSystem If Not $bFirstRun Then $tProcess = ($aTemp[$nProcStartKern] - $aStat[$nProcStartKern]) + ($aTemp[$nProcStartUser] - $aStat[$nProcStartUser]) $tSystem = ($aTemp[$nStartKernel] - $aStat[$nStartKernel]) + ($aTemp[$nStartUser] - $aStat[$nStartUser]) Else ProcessSetPriority(@AutoItPID, $nScriptPriority) $bFirstRun = False EndIf $aStat = $aTemp Return Int(Round(($tProcess / $tSystem) * 100)) EndFunc ;==>_ProcessCPU Edit - To give credit for source.
      Anonymous
    • n0pr0bl3m
      By n0pr0bl3m
      So I have some timers which I reset periodically, but my problem is that they don't wait for the functions before them to finish and in a strange way reset beforehand.

      -snip-

      timerinit doesnt wait the mouseclick and sleep functions to finish