AutoIT Geek Posted December 4, 2005 Share Posted December 4, 2005 (edited) i wrote a little code to check how fast are some autoit functions and i get ... well ... slow results the avarage result is in the order of 165000 + - microseconds expandcollapse popupOpt( "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 i use autoit functions and no magic expandcollapse popupOpt( "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 December 4, 2005 by AutoIT Geek Link to comment Share on other sites More sharing options...
w0uter Posted December 4, 2005 Share Posted December 4, 2005 bc. autoit = teh pwn i think it is bc. autoit provides more options/errorchecking. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
AutoIT Geek Posted December 4, 2005 Author Share Posted December 4, 2005 bc. autoit = teh pwn 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 codeusing HWND is the shortest way to do it.still, my code is more then 10 times faster, i checked and rechecked and triple checked 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 More sharing options...
Developers Jos Posted December 4, 2005 Developers Share Posted December 4, 2005 try it with Opt("MouseClickDelay", 0) at the top.... SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
AutoIT Geek Posted December 4, 2005 Author Share Posted December 4, 2005 intresting ... now, the autoit code avarage time is reduced to 16000 -> 20000 + - what an impact. my code runs at 9000 -> 13000 + - interesting. Link to comment Share on other sites More sharing options...
AutoIT Geek Posted December 5, 2005 Author Share Posted December 5, 2005 Opt WinWaitDelay of 0checked 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 -> 11000as i wrote before, interesting, this points me to seek more optimization for my code. im playing now with ControlGetHandle() , the autoit code is REALLY quick, 1500 microseconds + -a challange. Link to comment Share on other sites More sharing options...
Richard Robertson Posted December 6, 2005 Share Posted December 6, 2005 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now