Jump to content

Can you ppl confirm my results ?


AutoIT Geek
 Share

Recommended Posts

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

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...