Guten Abend zusammen,
aus aktuellem Anlass habe ich eine winzig kleine UDF geschrieben, welche es sehr einfach ermöglicht einen Timer zum Debuggen zu erstellen. Seht selbst:
_debugTimer.au3
Spoiler anzeigen
#include-once
$timer = False
; #FUNCTION# ====================================================================================================================
; Name ..........: _StartDebugTimer
; Description ...: Starts the timer. Necessary for all upcomming functions.
; Syntax ........: _StartDebugTimer([$consoleoutput = False])
; Parameters ....: $consoleoutput - [optional] Defines the output in the console with the time as suffix. Default is no output.
; Return values .: Success: True; Failure: False
; Author ........: ErrorKid @ autoit.de
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes. See DebugTimerDemo.au3
; ===============================================================================================================================
Func _StartDebugTimer($consoleoutput = False)
If $timer = False Then
Global $timer = TimerInit()
Global $lastcheckpoint = 0
If $consoleoutput Then
ConsoleWrite($consoleoutput & @CRLF)
EndIf
Return True
Else
ConsoleWrite("_debugTimer-Error: Timer already started. Stop it with _EndDebugTimer()" & @CRLF)
Return False
EndIf
EndFunc ;==>_StartDebugTimer
; #FUNCTION# ====================================================================================================================
; Name ..........: _DisplayCurrentTime
; Description ...: Displays the current time from the beginning of _StartDebugTimer() or from the last call from _DisplayCurrentTime() which had the value $fromlascheckpoint = True
; Syntax ........: _DisplayCurrentTime([$consoleoutput = False[, $fromlascheckpoint = False]])
; Parameters ....: $consoleoutput - [optional] Defines the output in the console with the time as suffix. Default is no output.
; $fromlascheckpoint - [optional] True = Returns/prints the time from the last call from _DisplayCurrentTime() which had the value $fromlascheckpoint = True. Default is the time from the beginning of _StartDebugTimer()
; Return values .: Success: The time what would be print if $consoleoutput <> False (see parameters); Failure: False
; Author ........: ErrorKid @ autoit.de
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes. See DebugTimerDemo.au3
; ===============================================================================================================================
Func _DisplayCurrentTime($consoleoutput = False, $fromlascheckpoint = False)
If $timer <> False Then
$time = TimerDiff($timer)
If $fromlascheckpoint Then
$time = $time - $lastcheckpoint
$lastcheckpoint = $time
EndIf
If $consoleoutput Then
ConsoleWrite($consoleoutput & $time & @CRLF)
EndIf
Return $time
Else
ConsoleWrite("_debugTimer-Error: Timer isn't started. Start it with _StartDebugTimer()" & @CRLF)
Return False
EndIf
EndFunc ;==>_DisplayCurrentTime
; #FUNCTION# ====================================================================================================================
; Name ..........: _EndDebugTimer
; Description ...: Closes the Timer. Works only after the call from _StartDebugTimer()
; Syntax ........: _EndDebugTimer([$consoleoutput = False])
; Parameters ....: $consoleoutput - [optional] Defines the output in the console with the time as suffix. Default is no output.
; Return values .: Success: True; Failure: False
; Author ........: ErrorKid @ autoit.de
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes. See DebugTimerDemo.au3
; ===============================================================================================================================
Func _EndDebugTimer($consoleoutput = False)
$time = TimerDiff($timer)
If $timer <> False Then
Global $timer = False
If $consoleoutput Then
ConsoleWrite($consoleoutput & $time & @CRLF)
EndIf
Return True
Else
ConsoleWrite("_debugTimer-Error: Timer isn't started. Start it with _StartDebugTimer()" & @CRLF)
Return False
EndIf
EndFunc ;==>_EndDebugTimer
DebugTimerDemo.au3
Spoiler anzeigen
#include <_debugTimer.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
_StartDebugTimer("Starting debugtimer!")
[/autoit] [autoit][/autoit] [autoit]Local $msg
_DisplayCurrentTime("Createt $msg, took: ", True)
GUICreate("My GUI")
_DisplayCurrentTime("GuiCreate() took: ", True)
GUISetState(@SW_SHOW)
_DisplayCurrentTime("GUISetState() took: ", True)
_EndDebugTimer()
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
_StartDebugTimer()
GUIDelete()
_DisplayCurrentTime("GUIDelete() took: ", True)
Es sollte eigentlich recht selbsterklärend sein. Habe versucht die Funktionen so genau wie möglich zu beschreiben. Falls es aber Probleme gibt kann ich gerne Helfen bzw. noch den Beispieltext kommentieren!
Grüße ErrorKid