Eigensheep Posted April 26, 2011 Posted April 26, 2011 Ok, I am genuinely confused by this. I'm using GDI Plus to draw images to the screen and then "moving" the images by redrawing them in GDI+. But the problem is that the script slows depending on how I define my initial variables and I don't see why - Like this, it's a useable script, reasonably fast and responsive ("local" here is the global scope, so I don't think memory is the problem) Local Const $Width = 700 Local Const $Height = 650 Local Const $fog = 8 Local Const $n_blocks = 30 Local Const $tilt = $Pi/5 Local Const $bgcolor = "F0506070" Local $dot_distance = 50 But like this and the whole script becomes around 3 seconds slower for every action Switch $split[1] Case "fog" Global Const $fog = 8 Case "n_blocks" Global Const $n_blocks = 30 Case "bgcolor" Global Const $bgcolor = "F0506070" Case "sphere_image" Global $sphere_image = @ScriptDir & "\images\sphere.gif" Case "sphereR0" Global $sphereR0 = 255 Case "sphereG0" Global $sphereG0 = 255 Case "sphereB0" Global $sphereB0 = 90 EndSwitch And, of course, I wanted to use the latter. Any ideas what I can do?
guinness Posted April 26, 2011 Posted April 26, 2011 Why not declare the variables at the top of the script and then change their values? Try and let me know. I also tend not to use Const unless I have to. Plus is this in a Function, because it would be best to use Local. Global $fog, $n_blocks, $bgcolor, $sphere_image, $sphereR0, $sphereG0, $sphereB0 Switch $split[1] Case "fog" $fog = 8 Case "n_blocks" $n_blocks = 30 Case "bgcolor" $bgcolor = "F0506070" Case "sphere_image" $sphere_image = @ScriptDir & "\images\sphere.gif" Case "sphereR0" $sphereR0 = 255 Case "sphereG0" $sphereG0 = 255 Case "sphereB0" $sphereB0 = 90 EndSwitch UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Info Posted April 26, 2011 Posted April 26, 2011 BTW, AFAIK variables with long names slow down the script.
Eigensheep Posted April 26, 2011 Author Posted April 26, 2011 That doesn't seem to have made a difference. The variable $split[1] comes from a FileReadLine() and the file is closed after the Switch loop, would this make a difference? And Info, I'll bear that in mind - how long is long? Thanks for the help guys.
Eigensheep Posted April 27, 2011 Author Posted April 27, 2011 I think I've found a solution. First I shortened some of my longer variables (this is surprising news!) and that made a small difference, BUT then I realised that because I was taking some variables from an external file, they were all being read as string type, so in expressions such as "If $var Then" later on, even if $var was "False" then the code was executed. This made a huge difference - it cut down the average time for one of my functions from 250ms to 79ms (according to timerdiff)...Now I know to make sure my variables are of the right type in future. Thanks for the tips though, I'll bear all of it in mind for future scripts.
jvanegmond Posted April 27, 2011 Posted April 27, 2011 You shouldn't shorten variable names because it is faster. Readability is a lot more important than optimization. Beside that, we can write a preprocessor which will shorten all variable names for you (like obfuscator does) so that your script executes faster. github.com/jvanegmond
KaFu Posted April 27, 2011 Posted April 27, 2011 You shouldn't shorten variable names because it is faster. Readability is a lot more important than optimization. Beside that, we can write a preprocessor which will shorten all variable names for you (like obfuscator does) so that your script executes faster.Fully aknowledged, you should better use OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
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