# [Solved] Calculate/Compare Functions speed ?

## Recommended Posts

Hey

I've these two functions to do a base64 conversation , Is there any way to compare the exact speed of both of them ?

```Func _Base64Encode(\$input)

\$input = Binary(\$input)

Local \$struct = DllStructCreate("byte[" & BinaryLen(\$input) & "]")

DllStructSetData(\$struct, 1, \$input)

Local \$strc = DllStructCreate("int")

Local \$a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr(\$struct), _
"int", DllStructGetSize(\$struct), _
"int", 1, _
"ptr", 0, _
"ptr", DllStructGetPtr(\$strc))

If @error Or Not \$a_Call[0] Then
Return SetError(1, 0, "") ; error calculating the length of the buffer needed
EndIf

Local \$a = DllStructCreate("char[" & DllStructGetData(\$strc, 1) & "]")

\$a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr(\$struct), _
"int", DllStructGetSize(\$struct), _
"int", 1, _
"ptr", DllStructGetPtr(\$a), _
"ptr", DllStructGetPtr(\$strc))

If @error Or Not \$a_Call[0] Then
Return SetError(2, 0, ""); error encoding
EndIf

Return DllStructGetData(\$a, 1)

EndFunc   ;==>_Base64Encode```

```Func _Base64Encode(\$sData)
Local \$oXml = ObjCreate("Msxml2.DOMDocument")
If Not IsObj(\$oXml) Then
SetError(1, 1, 0)
EndIf

Local \$oElement = \$oXml.createElement("b64")
If Not IsObj(\$oElement) Then
SetError(2, 2, 0)
EndIf

\$oElement.dataType = "bin.base64"
\$oElement.nodeTypedValue = Binary(\$sData)
Local \$sReturn = \$oElement.Text

If StringLen(\$sReturn) = 0 Then
SetError(3, 3, 0)
EndIf

Return \$sReturn
EndFunc   ;==>_Base64Encode```

Edited by DrAhmed

##### Share on other sites

@DrAhmed look at TimerInit() and TimerDiff() in the help file. You should be able to add that in to each of your functions to get an idea of the time they take.

√-1 2^3 ∑ π, and it was delicious!

##### Share on other sites
28 minutes ago, JLogan3o13 said:

@DrAhmed look at TimerInit() and TimerDiff() in the help file. You should be able to add that in to each of your functions to get an idea of the time they take.

Could you give me an example please ?

##### Share on other sites

@DrAhmed There is an awesome example...in the help file for TimerDiff:

Add a TimerInit() to the top of your function, and then a TimerDiff right before your Return statement, done.

√-1 2^3 ∑ π, and it was delicious!

##### Share on other sites

Hello.

```#include <String.au3>

Local \$sString = _StringRepeat("Hello Word", 1000)
Local \$hTimer = TimerInit()
For \$i = 1 To 100
_Base64Encode(\$sString)
Next
Local \$iDiff = TimerDiff(\$hTimer)

ConsoleWrite("_Base64Encode time elapsed: " & \$iDiff & @CRLF)

\$hTimer = TimerInit()
For \$i = 1 To 100
_Base64EncodeMsxml(\$sString)
Next
\$iDiff = TimerDiff(\$hTimer)

ConsoleWrite("_Base64EncodeMsxml time elapsed: " & \$iDiff & @CRLF)```

Saludos

AutoIt...

##### Share on other sites

Not exactly the "teach a man to fish" method, @Danyfirex

√-1 2^3 ∑ π, and it was delicious!

##### Share on other sites
15 minutes ago, JLogan3o13 said:

Not exactly the "teach a man to fish" method, @Danyfirex

mine is more like let them choose if want to learn  or want just the fish till teacher dies. lol

Saludos

AutoIt...

## Create an account

Register a new account

• ### Similar Content

• By Inpho
Hi All,
I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free.
String functions:
#AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, \$bHumanFormat = False]) ; Parameters ....: \$iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; \$bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet(\$iType = 1, \$bHumanFormat = False) If \$iType < 1 Or \$iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local \$sTime = @HOUR & ":" & @MIN & ":" & @SEC Local \$sDate = @MDAY & "/" & @MON & "/" & @YEAR If \$iType = 1 Then If \$bHumanFormat = False Then \$sTime = StringReplace(\$sTime, ":", "") \$sDate = StringReplace(\$sDate, "/", "") \$sDate = StringTrimLeft(\$sDate, 4) & StringMid(\$sDate, 3, 2) & StringLeft(\$sDate, 2) Return (\$sDate & "_" & \$sTime) Else Return (\$sDate & " " & \$sTime) EndIf ElseIf \$iType = 2 Then If \$bHumanFormat = False Then \$sDate = StringReplace(\$sDate, "/", "") \$sDate = StringTrimLeft(\$sDate, 4) & StringMid(\$sDate, 3, 2) & StringLeft(\$sDate, 2) EndIf Return (\$sDate) ElseIf \$iType = 3 Then If \$bHumanFormat = False Then \$sTime = StringReplace(\$sTime, "/", "") EndIf Return (\$sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension(\$sPath) ; Parameters ....: \$sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension(\$sPath) Return (StringTrimLeft(\$sPath, StringInStr(\$sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName(\$sPath[, \$bIncludeExtension = True]) ; Parameters ....: \$sPath - a string value. ; \$bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName(\$sPath, \$bIncludeExtension = True) Local \$sReturn = StringTrimLeft(\$sPath, StringInStr(\$sPath, "\", 0, -1)) If \$bIncludeExtension = False Then \$sReturn = StringLeft(\$sReturn, StringInStr(\$sReturn, ".", 0, -1) - 1) Return (\$sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath(\$sPath) ; Parameters ....: \$sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath(\$sPath) Return (StringLeft(\$sPath, StringInStr(\$sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft(\$sString, \$sRemove[, \$iCaseSense = 0, \$iOccurrence = 1]) ; Parameters ....: \$sString - a string value. The string to search inside. ; \$sRemove - a string value. The string to search for. ; \$iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; \$iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft(\$sString, \$sRemove, \$iCaseSense = 0, \$iOccurrence = 1) Return (StringLeft(\$sString, StringInStr(\$sString, \$sRemove, \$iCaseSense, \$iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom(\$iAmount[, \$iType = 1]) ; Parameters ....: \$iAmount - an integer value. Length of returned string ; \$iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - \$iAmount is not a positive integer ; 2 - \$iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom(\$iAmount, \$iType = 1) If \$iAmount < 1 Or IsInt(\$iAmount) = 0 Then Return (SetError(-1, 0, "")) Local \$sString = "" Local \$iRandomLow = 1, \$iRandomHigh = 62 #Tidy_Off Local Static \$aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If \$iType = 1 Then ;; digits: 1 - 10 \$iRandomHigh = 10 ElseIf \$iType = 2 Then ;; hexadecimal: 1 - 16 \$iRandomHigh = 16 ElseIf \$iType = 3 Then ;; alnumupper: 1 - 36 \$iRandomHigh = 36 ElseIf \$iType = 4 Then ;; alnum: 1 - 62 \$iRandomHigh = 62 ElseIf \$iType = 5 Then ;; alphaupper: 11 - 36 \$iRandomLow = 11 \$iRandomHigh = 36 ElseIf \$iType = 6 Then ;; alpha: 11 = 62 \$iRandomLow = 11 \$iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For \$i = 1 To \$iAmount \$sString &= \$aCharId[Random(\$iRandomLow, \$iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return (\$sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft(\$sString, \$sRemove[, \$iCaseSense = 0, \$iOccurrence = 1]) ; Parameters ....: \$sString - a string value. The string to search inside. ; \$sRemove - a string value. The string to search for. ; \$iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; \$iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft(\$sString, \$sRemove, \$iCaseSense = 0, \$iOccurrence = 1) Return (StringTrimLeft(\$sString, StringInStr(\$sString, \$sRemove, \$iCaseSense, \$iOccurrence) + StringLen(\$sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples:
ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)
• By Simpel
Hi,
I wanted to use _GetLogonTime() by guinness (https://www.autoitscript.com/forum/topic/19370-autoit-wrappers/?do=findComment&comment=942069).
#include <Date.au3> #include <Array.au3> ConsoleWrite(_GetLogonTime() & @LF) Func _GetLogonTime(\$sUserName = @UserName, \$sComputerName = @ComputerName) ; Idea by trancexx: http://www.autoitscript.com/forum/topic/113611-if-isadmin-not-detected-as-admin/ Local \$aRet = DllCall("netapi32.dll", "long", "NetUserGetInfo", "wstr", \$sComputerName, "wstr", \$sUserName, "dword", 11, "ptr*", 0) _ArrayDisplay(\$aRet) If @error Or \$aRet[0] Then Return SetError(1, 0, False) Local \$sHours = DllStructGetData(DllStructCreate("ptr;ptr;ptr;ptr;dword;dword;dword;ptr;ptr;dword;dword;dword;dword;ptr;dword;ptr;dword;dword;byte;dword", \$aRet[4]), 18) DllCall("netapi32.dll", "long", "NetApiBufferFree", "ptr", \$aRet[4]) Return _DateAdd("h", "-" & \$sHours, _NowCalc()) EndFunc ;==>_GetLogonTime It always returns false.
I displayed \$aRet:
[0]|2221
[1]|mycomputer
[2]|myuser
[3]|11
[4]|0x0000000000000000
\$aRet[4] shouldn't be 0x0000000000000000 right? Any help?

• Hello everyone, I am working on a project which requires reading a few values from Excel, the catch is that I need it to be very fast... unfortunatley I found out that read operations using the supplied Excel UDF are very slow, more than 150 ms for each operation on average
Here is my testing setup that I made:
#include <Excel.au3> #include <MsgBoxConstants.au3> Global \$iTotalTime = 0 Test() Func Test() Local \$oExcel = _Excel_Open() Local \$oBook = _Excel_BookAttach("Test.xlsx", "FileName", \$oExcel) Local \$sSheet = "Sheet1" If @error Then Return MsgBox(\$MB_ICONERROR, "Excel Failed", "Failed to attach to Excel") Local \$iNum For \$iRow = 1 To 6 Time() Local \$iNum = Number(_Excel_RangeRead(\$oBook, \$sSheet, "A" & \$iRow)) If (\$iNum = 1) Then ConsoleWrite("Row " & \$iRow & " is 1 and value of column B is " & _Excel_RangeRead(\$oBook, \$sSheet, "B" & \$iRow)) Else ConsoleWrite("Row " & \$iRow & " is not 1") EndIf ConsoleWrite(". Reading took: ") Time() Next ConsoleWrite("The whole operation took " & \$iTotalTime & " milliseconds." & @CRLF) EndFunc Func Time() Local Static \$hTimer Local Static \$bRunning = False If \$bRunning Then Local \$iTime = Round(TimerDiff(\$hTimer), 2) \$iTotalTime += \$iTime ConsoleWrite(\$iTime & @CRLF) Else \$hTimer = TimerInit() EndIf \$bRunning = Not \$bRunning EndFunc And Test.xlsx in CSV format:
1,-1 -1,1 1,-1 1,1 -1,-1 1,1 Here is the actual xlsx but it should expire in a week: https://we.tl/t-EVkxGp1kc6
And finally output from my script:
Row 1 is 1 and value of column B is -1. Reading took: 276.06 Row 2 is not 1. Reading took: 163.36 Row 3 is 1 and value of column B is -1. Reading took: 302.58 Row 4 is 1 and value of column B is 1. Reading took: 294.65 Row 5 is not 1. Reading took: 152.33 Row 6 is 1 and value of column B is 1. Reading took: 284.92 The whole operation took 1473.9 milliseconds.
Taking ~1.5 seconds for reading 6 rows of data is bad for my script, which needs to run as fast as possible . It would be nice if I can bring this down to 100 ms somehow, I am not very experienced working with MS office so I thought about asking you folks for help and advice on how I can optimize my script to squeeze out every bit of performance that I can get from this script

Thanks for the help in advance!
• By Skeletor
Hey All,
I'm trying to set the date using a variable.
Basically, I set the date into the input box, then I change the input box, say, I change the year.
Then I set what I typed into the input box into the Date Picker.

This is a demo code.
#include <ButtonConstants.au3> ;Start GUI includes #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #Region ### START Koda GUI section ### Form= \$Form1 = GUICreate("Form1", 615, 438, 192, 124) \$Date1 = GUICtrlCreateDate("2019/02/02 23:16:26", 80, 64, 186, 21, \$DTS_SHORTDATEFORMAT) \$Input1 = GUICtrlCreateInput("Input1", 80, 152, 185, 21) \$Button1 = GUICtrlCreateButton("Set data", 176, 96, 75, 25) \$Button2 = GUICtrlCreateButton("Read from input", 176, 200, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 \$nMsg = GUIGetMsg() Switch \$nMsg Case \$GUI_EVENT_CLOSE Exit Case \$Button1 \$Read = GUICtrlRead(\$Date1) GUICtrlSetData(\$Input1, \$Read) MsgBox(-1, "", \$Read) Case \$Button2 \$Read = GUICtrlRead(\$Input1) \$New_date = StringReplace(\$Read, "/", "") \$DAY = StringLeft(\$New_date, 2) \$MON = StringMid(\$New_date, 4, 3) \$YEAR = StringRight(\$New_date, 4) MsgBox(-1, "", \$DAY & \$MON & \$YEAR) ;_GUICtrlDTP_SetFormat(\$hWndDate, "yyyy/MM/dd") \$DateFormate = (\$DAY & " " & \$MON & " " & \$YEAR) \$DTM_SETFORMAT_ = 0x1032 ; \$DTM_SETFORMATW GUICtrlSendMsg(\$Date1, \$DateFormate, 0, "MM/dd/yyyy") EndSwitch WEnd

• I forgot an important and needed aspect of my code. I need to be able to check for people who work every other week. Is it possible to write the dates that they work (every other week) between two date ranges?
Example:  Bob Smith has a Start date of 8-26-2018 (that is the date he is hired) And He stops working on 12-12-18 (that's the day he goes on vacation or whatever) However his work shift is every other Saturday from 7:30 AM to 6:00 Pm.  I need to calculate every other Saturday between 8-26-18 and 12-12-18 (is this clear?)

here is the code I have so far. I am just missing this last part:
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...