# [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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

##### 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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

##### 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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

##### 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 Dan_555
Hi, here are few functions for the ListBox.
I have searched the forum, but most of the functions are for listview, so i took one example code from melba23 (clear selection) and
wrote few more functions. (Because my current project needs them).

These functions work only on a Multi-selection ListBox .
Edit: Only 1 function does not work with single selection box.
The functions do: Clear Selection, Delete Selected items, Invert Selection, Move selected items up and down.
The example code has 2 Listboxes. The selected items on the left ListBox can be moved up and down. The right Listbox has buttons for the other functions.
#include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Array.au3> Local \$singlesel = 0, \$iMsgBoxAnswer = 0 ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question, Modality=Task Modal \$iMsgBoxAnswer = MsgBox(8228, "Choose Listbox selecton type", "Yes for single, No for multi selection box") If \$iMsgBoxAnswer = 6 Then \$singlesel = 1 ;Yes Local \$BL_1,\$BL_2,\$BR_1,\$BR_2,\$BR_3,\$BR_4,\$BR_5,\$BR_6 Global \$hForm1 = GUICreate("Listbox test", 349, 287) \$LB_1 = GUICtrlCreateList("", 6, 40, 157, 244, BitOR(\$LBS_NOTIFY, \$LBS_MULTIPLESEL, \$WS_HSCROLL, \$WS_VSCROLL, \$LBS_DISABLENOSCROLL)) If \$singlesel = 1 Then \$LB_2 = GUICtrlCreateList("", 179, 40, 157, 244, BitOR(\$LBS_NOTIFY, \$WS_HSCROLL, \$WS_VSCROLL, \$LBS_DISABLENOSCROLL)) Else \$LB_2 = GUICtrlCreateList("", 179, 40, 157, 244, BitOR(\$LBS_NOTIFY, \$LBS_MULTIPLESEL, \$WS_HSCROLL, \$WS_VSCROLL, \$LBS_DISABLENOSCROLL)) \$BR_3 = GUICtrlCreateButton("Reverse Sel", 272, 22, 68, 17) EndIf \$BL_1 = GUICtrlCreateButton("Up", 20, 3, 35, 18) \$BL_2 = GUICtrlCreateButton("Down", 60, 3, 35, 18) \$BR_1 = GUICtrlCreateButton("Up", 200, 3, 35, 18) \$BR_2 = GUICtrlCreateButton("Down", 240, 3, 35, 18) \$BR_4 = GUICtrlCreateButton("Clear Sel", 217, 22, 52, 17) \$BR_5 = GUICtrlCreateButton("Delete", 175, 22, 40, 17) \$BR_6 = GUICtrlCreateButton("Populate", 290, 3, 50, 18) GUISetState(@SW_SHOW) For \$x = 0 To 50 If \$x <= 10 Then GUICtrlSetData(\$LB_1, \$x & " test", 0) GUICtrlSetData(\$LB_2, \$x & " Test", 0) Next While 1 \$nMsg = GUIGetMsg() Switch \$nMsg Case \$GUI_EVENT_CLOSE Exit Case \$BL_1 \$a = Listbox_ItemMoveUD(\$LB_1, -1) If \$a > -1 Then WinSetTitle(\$hForm1, "", "Moved items: " & \$a) Case \$BL_2 \$a = Listbox_ItemMoveUD(\$LB_1, 1) If \$a > -1 Then WinSetTitle(\$hForm1, "", "Moved items: " & \$a) Case \$BR_1 Listbox_ItemMoveUD(\$LB_2, -1) Case \$BR_2 Listbox_ItemMoveUD(\$LB_2, 1) Case \$BR_3 Listbox_ReverseSelection(\$LB_2) Case \$BR_4 Listbox_ClearSelection(\$LB_2) Case \$BR_5 Listbox_DeleteSelectedItems(\$LB_2) Case \$BR_6 ;Populate GUICtrlSetData(\$LB_2, "") ; Clears the listbox For \$x = 0 To 50 GUICtrlSetData(\$LB_2, \$x & " Test", 0) Next EndSwitch WEnd ;note \$hLB_ID - is the Listbox id Func Listbox_DeleteSelectedItems(\$hLB_ID) Local \$aSel = _GUICtrlListBox_GetSelItems(\$hLB_ID) ;Get selected items Local \$i, \$slb = 0, \$y, \$x If \$aSel[0] = 0 Then ;If the array is empty, there is no selection, or it is a single selection listbox For \$x = 0 To _GUICtrlListBox_GetCount(\$hLB_ID) - 1 \$y = _GUICtrlListBox_GetSel(\$hLB_ID, \$x) If \$y = True Then \$slb = 1 _GUICtrlListBox_DeleteString(\$hLB_ID, \$x) ;Perform a delete on single sel. LB ExitLoop EndIf Next EndIf If \$slb = 0 Then _GUICtrlListBox_BeginUpdate(\$hLB_ID) For \$i = \$aSel[0] To 1 Step -1 ;Loop backwards and delete the selected items _GUICtrlListBox_DeleteString(\$hLB_ID, \$aSel[\$i]) Next _GUICtrlListBox_EndUpdate(\$hLB_ID) EndIf EndFunc ;==>Listbox_DeleteSelectedItems Func Listbox_ClearSelection(\$hLB_ID) ;Removes the selection from multi and single selection ListBox Local \$aSel = _GUICtrlListBox_GetSelItems(\$hLB_ID) ;Code from Melba23 - Autoit Forum Local \$slb, \$x, \$y If \$aSel[0] = 0 Then _GUICtrlListBox_SetCurSel(\$hLB_ID, -1) \$slb = 1 EndIf If \$slb = 0 Then _GUICtrlListBox_BeginUpdate(\$hLB_ID) For \$i = 1 To \$aSel[0] _GUICtrlListBox_SetSel(\$hLB_ID, \$aSel[\$i], False) Next _GUICtrlListBox_EndUpdate(\$hLB_ID) EndIf EndFunc ;==>Listbox_ClearSelection Func Listbox_ReverseSelection(\$hLB_ID) ;Logically, this function works only on multi-selection listboxes Local \$i Local \$aCou = _GUICtrlListBox_GetCount(\$hLB_ID) Local \$cSel = _GUICtrlListBox_GetCaretIndex(\$hLB_ID) ;Save the caret _GUICtrlListBox_BeginUpdate(\$hLB_ID) For \$i = 0 To \$aCou _GUICtrlListBox_SetSel(\$hLB_ID, \$i, Not (_GUICtrlListBox_GetSel(\$hLB_ID, \$i))) Next _GUICtrlListBox_SetCaretIndex(\$hLB_ID, \$cSel) ;Restore the caret _GUICtrlListBox_EndUpdate(\$hLB_ID) EndFunc ;==>Listbox_ReverseSelection Func Listbox_ItemMoveUD(\$hLB_ID, \$iDir = -1) ;Listbox_ItemMoveUD - Up/Down Move Multi/Single item in a ListBox ;\$iDir: -1 up, 1 down ;Return values -1 nothing to do, 0 nothing moved, >0 performed moves Local \$iCur, \$iNxt, \$aCou, \$aSel, \$i, \$m = 0, \$y, \$slb = 0 ;Current, next, Count, Selection, loop , movecount \$aSel = _GUICtrlListBox_GetSelItems(\$hLB_ID) ;Put selected items in an array \$aCou = _GUICtrlListBox_GetCount(\$hLB_ID) ;Get total item count of the listbox If \$aSel[0] = 0 Then \$y = _GUICtrlListBox_GetCurSel(\$hLB_ID) If \$y > -1 Then _ArrayAdd(\$aSel, \$y) \$aSel[0] = 1 \$slb = 1 EndIf EndIf ;WinSetTitle(\$hGUI, "", \$aSel[0]) ;Debugging info Select Case \$iDir = -1 ;Move Up For \$i = 1 To \$aSel[0] If \$aSel[\$i] > 0 Then \$iNxt = _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i] - 1) ;Save the selection index - 1 text _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i] - 1, _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i])) ;Replace the index-1 text with the index text _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i], \$iNxt) ;Replace the selection with the saved var \$m = \$m + 1 EndIf Next For \$i = 1 To \$aSel[0] ;Restore the selections after moving If \$aSel[\$i] > 0 Then If \$slb = 0 Then _GUICtrlListBox_SetSel(\$hLB_ID, \$aSel[\$i] - 1, 1) Else _GUICtrlListBox_SetCurSel(\$hLB_ID, \$aSel[\$i] - 1) EndIf EndIf Next Return \$m Case \$iDir = 1 ;Move Down If \$aSel[0] > 0 Then For \$i = \$aSel[0] To 1 Step -1 If \$aSel[\$i] < \$aCou - 1 Then \$iNxt = _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i] + 1) _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i] + 1, _GUICtrlListBox_GetText(\$hLB_ID, \$aSel[\$i])) _GUICtrlListBox_ReplaceString(\$hLB_ID, \$aSel[\$i], \$iNxt) \$m = \$m + 1 EndIf Next EndIf For \$i = \$aSel[0] To 1 Step -1 ;Restore the selections after moving If \$aSel[\$i] < \$aCou - 1 Then If \$slb = 0 Then _GUICtrlListBox_SetSel(\$hLB_ID, \$aSel[\$i] + 1, 1) Else _GUICtrlListBox_SetCurSel(\$hLB_ID, \$aSel[\$i] + 1) EndIf EndIf Next Return \$m EndSelect Return -1 EndFunc ;==>Listbox_ItemMoveUD
• By Jahar
Hi All,
Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.

• Hi everyone,
I am bit stumped as to why I am not able to set the time in the Date control
#include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local \$idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, \$DTS_TIMEFORMAT) ; to select a specific default format Local \$sStyle = "HH:mm:ss" GUICtrlSendMsg(\$idDate, \$DTM_SETFORMATW, 0, \$sStyle) ; Set time Local \$iRet = GUICtrlSetData(\$idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & (\$iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> \$GUI_EVENT_CLOSE WEnd MsgBox(\$MB_SYSTEMMODAL, "Time", GUICtrlRead(\$idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
But I get failure
What gives?
Thanks for the help in advance!

• Hi guys, i want to convert WebKit/Chrome timestamps that i've found in chrome cookie database to Human-Readable time (if possible, with UTC or GMT offset).
Example of WebKit/Chrome timestamp: 13228999534132232 Output that i want: 2020-03-18 20:16:56 This site has a tool to do this work, but i wonder how to convert this time (this timestamp's time bases are 1600/01/01) to human-readable time:
https://www.epochconverter.com/webkit

• This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.20 contains 197 functions divided into these topics:
window, desktop and monitor mouse and GUI GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
×

• Wiki

• Back

• #### Beta

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