How to optimize the speed of a script as much as possible.
http://ahkscript.org....php?f=6&t=6413
autohotkey.com is deprecated. The download page, the online documentation and the forum boards are either outdated or broken and everyone is recommended to move there.
I've read that SendInput and SendPlay perform faster than the default SendEvent. Is this true? What's the fastest between Input and Play then? What if I'm using "SetKeyDelay, -1" with SendEvent?
Yes, Play is faster then Event but there is something which can be more faster and that is Windows clipboard.
You would have noticed how fast Ctrl+V copies the vast text from clipboard to any application.
To use Windows clipboard as an alternative for Send , you can search Clip() or make your own simple function like
;SendClip("this is text") ;return SendClip(Data){ oldclip := ClipboardAll , Clipboard := Data Send, ^v Clipboard := oldclip }
I don't understand the difference between "SetMouseDelay, 0" and "SetMouseDelay, -1". Which one should I use for more speed/less delays?
Use -1
Is there a difference if the source of my script uses capital letters or not speed wise? Like, maybe AHK can interpret them faster if they are in some specific way. I usually type sources completely in lowercase
Not sure. shouldn't be
Does #NoEnv make a difference in speed?
It should. NoEnv disables Environment variables .
I use MPRESS to encrypt some of my compiled scripts. I know for sure that the startup time of the program gets slowed down, but are the functions of my program being slowed down too?
No. I think the binaries are decompressed in memory and so there is start up lag. Non-autoexecute sections like functions should be normal.
Is there a difference between AHK L and AHK basic for these commands speed wise?
Is it bad if I'm using a 32bit script on a 64bit machine instead of a 64bit script on a 64bit machine speed wise?
Is there a difference between using an Unicode script and an ANSI script speed wise?
No/Minimal for me
Now a CS Undergrad. | My Website | Autohotkey Scripts | Softwares
Telegram me : @aviaryan
Thanks for the idea, but for what I need, not only real keyboard inputs must be simulated but also mouse clicks, and the clipboard is unusable.Yes, Play is faster then Event but there is something which can be more faster and that is Windows clipboard.
You would have noticed how fast Ctrl+V copies the vast text from clipboard to any application.
To use Windows clipboard as an alternative for Send , you can search Clip() or make your own simple function like
I've asked this because I know an advanced EXE packer called Themida that can virtualize each single API call within the program to encrypt, and as a result it slows down all the functions of the program, but I doubt that the more basic EXE compression tools such as MPRESS and UPX affect this.No. I think the binaries are decompressed in memory and so there is start up lag. Non-autoexecute sections like functions should be normal.
There is Click and MouseMove command for Mouse Clicks, use it with SetMouseDelay, -1.
That's the best you can get
TI've asked this because I know an advanced EXE packer called Themida that can virtualize each single API call within the program to encrypt, and as a result it slows down all the functions of the program, but I doubt that the more basic EXE compression tools such as MPRESS and UPX affect this.
They probably dont, for me. I use UPX all the time.
Now a CS Undergrad. | My Website | Autohotkey Scripts | Softwares
Telegram me : @aviaryan
If anyone can help me for the others, I will be grateful!
Is there a difference if the source of my script uses capital letters or not speed wise? Like, maybe AHK can interpret them faster if they are in some specific way. I usually type sources completely in lowercase.
No matter how you type it, Autohotkey will process variables, goto locations, etc into memory addresses before the script starts running. This won't take a noticeable amount of time.
As for the automation stuff (sending clicks/keys), I wouldn't worry about speed there. AutoHotkey can already send input faster than most applications can respond to it.
You should be using AutoHotkey for its ease of use. If you have a legit need to design an extremely fast application, you'll want to use a compiled rather than interpreted language.
Join us at the new forum - http://www.ahkscript.org/
Hello. A related question.
Does anyone know if there's any small speed difference between the first two examples below?
My question refers specifically to the speed of the if line. Are comparisons involving a 'hard coded' string faster or slower than comparisons with variables?
varInput := "Hello" varPassword := "Hello" if (varInput = varPassword) MsgBox Match!
and
varInput := "Hello" if (varInput = "Hello") MsgBox Match!
I'm asking this because I wonder if there is a performance hit when running hundreds of lines of code written as below. It's a style I use quite a lot:-
flagHappy := "WhateverHere" ;the values aren't used, they're just a unique identifier flagSad := "AnythingHere" varHowIAmFeeling := flagHappy if (varHowIAmFeeling = flagHappy) { Msgbox Woohoo! } else if (varHowIAmFeeling = flagSad) { Msgbox Awwwww! }
Thanks for reading,
Mark
3. Using the Fast parameter of PixelSearch
PixelSearch, blablablabla, Fast
Using gdi pixel search is considerably faster than using the included PixelSearch function. There are some GDIP pixel search libraries available on the forum.
You can also turn off ListLines as mentioned here: Script Performance:
ListLines, Off
Also, SetTitleMatch to match only exactly might make those operations a bit faster? (not confirmed)
SetTitleMatchMode, 3 ;A window's title must exactly match WinTitle to be a match.
Also not confirmed, but for scripts that have a lot of stuff or a lot of timers perhaps could increase number of threads from default of 10 to 20.
#MaxThreads 20 ; increase from default of 10
Also, from http://www.autohotke...Performance.htm
To maximize performance, avoid using SetFormat
#MaxThreads 20 ; increase from default of 10Also, from http://www.autohotke...Performance.htm
This is a bit of a detour, but last year I increased this value (can't remember the number I used, but it wasn't anything stupidly high) in a very complex script of mine and I started getting all of these really weird errors. Like variables and clipboards would be overwritten or changed with hexidecimal values. I did have a heap of variables with hex values, but the ones being overwritten never should have had these values. As soon as I changed this (and only this) value back the problems instantly stopped. This is a pretty useless post with no evidence, but I originally did a search and didn't find anything relating to it..
Seems that using short variable names and short function names can yield a 5-20% performance boost when those variables/functions are used repeatedly such as in a Loop or array iteration.
What about an option in the AutoHotkey interpreter to replace all the variable and functions name in the script with short ones before loading a script? (obviously would make it hard to debug via MyListVars and ListLines - but most of the time these are not needed). I really like using long-descriptive-friendly variable and function names when coding, but don't want to have to take a performance hit for making my code easy to read.
Supporting data from AutoIt:
http://www.autoitscr...ze/#entry717285
TEST: Variable name "sVeryMuchLongerVariable" vs "sShort": 5% slower
http://www.autoitscr...e-2#entry729583
TEST: Function call "short()" vs "VeryMuchLongerFunctionName()": 16% slower
No matter how you type it, Autohotkey will process variables, goto locations, etc into memory addresses before the script starts running. This won't take a noticeable amount of time.
@robertcollier4 AutoIt is not AutoHotkey. Test this yourself. There is not a significant difference between short and long variable names in AutoHotkey, because they're translated to memory addresses before the script starts.
start1 := A_TickCount Loop, 10000000 i := 1 end1 := A_TickCount start2 := A_TickCount Loop, 10000000 i_am_a_very_long_variable_name := 1 end2 := A_TickCount Msgbox % end1-start1 "`n" end2-start2
Note: dynamic variable references (using %% around a var) must be looked up at runtime - here you will see a performance hit for long variable names.
short := "i" long := "i_am_a_very_long_variable_name" start1 := A_TickCount Loop, 10000000 %short% := 1 end1 := A_TickCount start2 := A_TickCount Loop, 10000000 %long% := 1 end2 := A_TickCount Msgbox % end1-start1 "`n" end2-start2
Also note the same translation to memory addresses takes place for functions - again there is no significant difference between using long and short function names:
start1 := A_TickCount Loop, 10000000 i() end1 := A_TickCount start2 := A_TickCount Loop, 10000000 i_am_a_very_long_function_name() end2 := A_TickCount Msgbox % end1-start1 "`n" end2-start2 i_am_a_very_long_function_name() { return 1 } i() { return 1 }
Join us at the new forum - http://www.ahkscript.org/
You can also turn off ListLines as mentioned here: Script Performance:
ListLines, Off
learn something new every day! thanks
In addition to ListLines
, there is also KeyHistory
(if the script registers keypresses):
#KeyHistory 0
New Autohotkey forum: http://ahkscript.org.
Loop your test by thousands and average to get better results... You're also getting into the realm where other running processes will have large effects on your tests, so watch out for that