Sign in to follow this  
Followers 0
AutoIT Geek

Can you ppl confirm my results ?

7 posts in this topic

#1 ·  Posted (edited)

i wrote a little code to check how fast are some autoit functions and i get ... well ... slow results :P

the avarage result is in the order of 165000 + - microseconds

Opt( "TRayIconDebug", 1 )


Global $Frequency[ 2 ], $Start[ 2 ], $Stop[ 2 ], $Results[ 11 ], $i



For $i = 0 To 9

    Run( 'Calc.exe' )
    
    WinWaitActive( 'Calculator' )

                $WindowHandle = DllCall( 'USER32.DLL', 'hwnd', 'FindWindow', 'int', 0, 'str', 'Calculator' )
    
    
    $Start = DllCall( 'kernel32.dll', 'int', 'QueryPerformanceCounter', 'long_ptr', $Start[ 1 ] )
    
    
    $ControlHandle = ControlGetHandle( $WindowHandle[ 0 ] , '', 'Button42' )
    
    ControlClick( $WindowHandle[ 0 ] , '', $ControlHandle )
    
    $ControlHandle = ControlGetHandle( $WindowHandle[ 0 ] , '', 'Button47' )
    
    ControlClick( $WindowHandle[ 0 ] , '', $ControlHandle )
    
    $ControlHandle = ControlGetHandle( $WindowHandle[ 0 ] , '', 'Button52' )
    
    ControlClick( $WindowHandle[ 0 ] , '', $ControlHandle )
    
    
    $Stop = DllCall( 'kernel32.dll', 'int', 'QueryPerformanceCounter', 'long_ptr', $Stop[ 1 ] )
    

    $Results[ $i ] = $Stop[ 1 ] - $Start[ 1 ]
    
    MsgBox( 0, 'Time', $Results[ $i ] )

    WinClose( 'Calculator' )
    
Next


For $i = 0 To 9
    
    $Results[ 10 ] += $Results[ $i ]
    
Next


MsgBox( 0, 'Avarage Result', $Results[ 10 ] / 10 )

now, i wrote my own code that does the same thing and ... im a bit confused ... my code is about 10 times or more faster, the avarage result is 15000 or less microsecond :lmao: i use autoit functions and no

magic

Opt( "TRayIconDebug", 1 )



Func Buttonclick( $TopWinHandle, $ControlHandle )
    
    Local $CurrentThread[ 1 ], $RemoteThread[ 3 ], $Result[ 4 ]
    
    
    
    $CurrentThread = DllCall( 'kernel32.dll', 'int', 'GetCurrentThreadId' )
    
    $RemoteThread = DllCall( 'user32.dll', 'int', 'GetWindowThreadProcessId', 'hwnd', $ControlHandle, 'long_ptr', $RemoteThread )

    $Result = DllCall( 'user32.dll', 'int', 'AttachThreadInput', 'int', $CurrentThread[ 0 ], 'int', $RemoteThread[ 0 ], 'int', 1 )

    $Result = DllCall( 'user32.dll', 'hwnd', 'SetActiveWindow', 'hwnd', $TopWinHandle )
    
    $Result = DllCall( 'user32.dll', 'int', 'PostMessage', 'hwnd', $ControlHandle, 'int', 0x00F5 ); BM_CLICK
    
    $Result = DllCall( 'user32.dll', 'int', 'AttachThreadInput', 'int', $CurrentThread[ 0 ], 'int', $RemoteThread[ 0 ], 'int', 0 )
    
    
EndFunc 



Global $Frequency[ 2 ], $Start[ 2 ], $Stop[ 2 ], $Results[ 11 ], $i



For $i = 0 To 9

    Run( 'Calc.exe' )
    
    WinWaitActive( 'Calculator' )
    
    
;$WindowHandle = GetTopWindow( 'Calculator' )
    
    $WindowHandle = DllCall( 'USER32.DLL', 'hwnd', 'FindWindow', 'int', 0, 'str', 'Calculator' )
    
    
    $Start = DllCall( 'kernel32.dll', 'int', 'QueryPerformanceCounter', 'long_ptr', $Start[ 1 ] )
    
    
    $ControlHandle = ControlGetHandle( 'Calculator', '', 'Button42' )
    
    Buttonclick( $WindowHandle[ 0 ], $ControlHandle )
    
    $ControlHandle = ControlGetHandle( 'Calculator', '', 'Button47' )
    
    Buttonclick( $WindowHandle[ 0 ], $ControlHandle )
    
    $ControlHandle = ControlGetHandle( 'Calculator', '', 'Button52' )
    
    Buttonclick( $WindowHandle[ 0 ], $ControlHandle )
    
    
    $Stop = DllCall( 'kernel32.dll', 'int', 'QueryPerformanceCounter', 'long_ptr', $Stop[ 1 ] )
    
    $Results[ $i ] = $Stop[ 1 ] - $Start[ 1 ]
    
    MsgBox( 0, 'Time', $Results[ $i ] )
    
    WinClose( 'Calculator' )

Next


For $i = 0 To 9
    
    $Results[ 10 ] += $Results[ $i ]
    
Next



MsgBox( 0, 'Avarage Result', $Results[ 10 ] / 10 )

how come a code writen in c++ directly ( and i assume was optimized by the compiler ) is SLOWER then the code writen with autoit ? :):(

Edited by AutoIT Geek

Share this post


Link to post
Share on other sites



bc. autoit = teh pwn :lmao:

i think it is bc. autoit provides more options/errorchecking.

hhmmmm .. well, as you can see, the function im timing is ControlClick()

i wrote the code so the function will not search for anything and deal right away with HWND,

the same i did with my own code

using HWND is the shortest way to do it.

still, my code is more then 10 times faster, i checked and rechecked and triple checked :P

and my code is not c++

strange.

i expected to be at list as good as the function it self or maybe a bit slower, not this much better for uncompiled autoit code

Share this post


Link to post
Share on other sites

intresting ...

now, the autoit code avarage time is reduced to 16000 -> 20000 + -

what an impact.

my code runs at 9000 -> 13000 + -

interesting. :P

Share this post


Link to post
Share on other sites

Opt WinWaitDelay of 0

checked it, this actually hurts the autoit code, 13000 -> 25000 + -

and WinWaitDelay of 5 makes the best results 9500 -> 14000 + -

it makes my code run a bit faster, 7500 -> 11000

as i wrote before, interesting, this points me to seek more optimization for my code. :lmao:

im playing now with ControlGetHandle() , the autoit code is REALLY quick, 1500 microseconds + -

a challange. :P

Share this post


Link to post
Share on other sites

You do have to remember, AutoIt wasn't meant to run fast. It was meant to serve a purpose is a reasonable amount of time. I think it runs just fine.

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