A Collection of Techniques for Speeding Up Your AutoHotkey Scripts
I recently received the follow message from an AutoHotkey user perusing my blogs:
Jack, you can’t post false statements like this:
“However, the ternary does not provide better performance than the traditional If-Then-Else statement format.”
The ternary operator is inarguably faster than if/else and I encourage you to try this yourself.
I recently switched the core logic of my JSON parser from If/Else to ternary and saw an incredible speed increase. To the point where I only use If/If Else/Else statements when absolutely necessary (Ex: If I must have a loop in the middle of a check).
You can code entire blocks using nothing but ternary as long as you use proper parentheses, commas, and function calls.
There is a very well done AHK forum post that covers script optimizations and they report that ternary performs FORTY PERCENT FASTER than if/else statements.
Not sure if hyperlinks are allowed in these comments, so instead I’ll advise googling “AHK How to optimize the speed of a script as much as possible.” The first result should be the article in question. Pages 1 and 4 have tons of script speed gold in them.
I hope you’ll consider correcting/updating this article.
Groggy OtterComment on “AutoHotkey Toggles and the Ternary Operator”
I wrote that blog five years ago and I don’t know that I was talking about performance speed. I think I was referring to how the two expressions operate. In any case, I used a poor choice of words and have drawn a line through the comment.Continue reading