Sign in to follow this  
Followers 0
prazetto

Functions < Speedtest

2 posts in this topic

#1 ·  Posted (edited)

How the best way to test speed of my UDF's or Functions?

Yeah, Here.. here.. I have... :)

Lets go to play....

Initial : Speed value of first calling function.

Lowest. : Speed value of lowest calling function.

Fastest : Speed value of fastest calling function.

Average : Speed value of average calling function.

Lower value mean fastest execution time and called Fastest.

Higher value mean lowest execution time and called lowest.

speedtest.au3

; 15 Jan 2011

#include <yourUDFs.au3>

ConsoleWrite(speedtest(100))

Func speedtest($lap=100000)
    Local $test
    Local $loop, $start, $dif, $procent, $avg = 0
    Local $initial, $fastest = 0.9, $lowest = 0.00000000000000001
    For $loop = 1 To $lap
        $start = TimerInit()

        $test = apistrtolower("SPEEDTEST")      ; CHANGE! This line with your functions UDF's to test the speed

        $dif = TimerDiff($start)
        If $loop == 1 Then $initial = $dif
        If $lowest <= $dif Then $lowest = $dif
        If $fastest >= $dif Then $fastest = $dif
        $avg += $dif
        $procent = Floor($loop / $lap * 100)
        ConsoleWrite($dif & "   " & processbar($procent,100) & "    " & $procent & "%" & @CRLF)
        Next
    $avg = $avg / $lap
    Return "Initial:    " & $initial & " ms"& @CRLF &"Lowest.:  " & $lowest & " ms"& @CRLF &"Fastest:   " & $fastest & " ms" & @CRLF &"Average: " & $avg & " ms" & @CRLF
EndFunc

Func processbar($val, $nval,$nbar=25)
    Local $lim = Floor($nval / $nbar), $ret
    $ret = str_repeat(":",$val / $lim)
    $ret = "." & $ret & str_repeat(" ",Floor($nbar - StringLen($ret))) & "."
    Return $ret
EndFunc

Func str_repeat($input, $multiplier=0)
    Local $str, $loop
    $str = ""
    If $multiplier >= 1 Then
        For $loop = 1 To $multiplier Step +1
            $str &= $input
            Next
        EndIf
    Return $str
EndFunc

yourUDFs.au3

#include-once

Local $initial = DllOpen("user32.dll")

Func apistrtolower($str)
    $str = DllCall($initial,"wstr","CharLowerW","wstr",$str)
    Return $str[0]
EndFunc

Func apistrtolower2($str)
    $str = DllCall("user32.dll","wstr","CharLowerW","wstr",$str)
    Return $str[0]
EndFunc

Download as single rar file: speedtest.rar

apistrtolower()

Initial : 0.0507222118056147 ms

Lowest. : 0.0534971960386589 ms

Fastest: : 0.0194548894608553 ms

Average: : 0.020928256089454 ms

apistrtolower2()

Initial : 0.0525597013653332 ms

Lowest. : 0.0822332827654388 ms

Fastest : 0.0231298685802922 ms

Average : 0.0246274225714627 ms

More example of the return value of speed test,

StringCompare()

StringCompare($string1, $string2, 0)

Average : 0.00258000293182151

StringCompare($string1, $string2, 2) <-- Better

Average : 0.00247875281676456

StringInStr()

StringInStr($string,$substring,0,$occurrence, $start, $count) <-- Better

Average : 0.00486000552273355

StringInStr($string,$substring,2,$occurrence, $start, $count)

Average : 0.00504750573580197

StringReplace()

StringReplace($string, $searchstring_start, $replacestring, $occurrence, 0)

Average : 0.00686625780256568

StringReplace($string, $searchstring_start, $replacestring, $occurrence, 2) <-- Better

Average : 0.00459000521591502

Edited by prazetto

# Button. Progressbar - Graphical AutoIt3 Control (UDF) # GTK on AutoIt3 - GTK+ Framework | Widgets

Share this post


Link to post
Share on other sites



how about a full script?

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