Jump to content

[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
Link to comment
Share on other sites

  • Moderators

@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

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

@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

How to get your question answered on this forum!

Link to comment
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

Link to comment
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

 

 

Link to comment
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
 Share

×
×
  • Create New...