Mat Posted May 28, 2009 Posted May 28, 2009 (edited) Here are a few questions I have been meaning to ask about the efficiency of a script. 1) Is it more efficient to have lots of variables, or lots of functions? Right now I have 50 lines of declaring global variables for my programs defaults. Would it be better to simply call iniread every time I need it? I am presuming mathod 2 will mean a lower cpu when not in use, but 1 will give a lower cpu when in use?? 2) I know its an old debate, but which is more efficient, GUIGetMsg or set on event? Or could I do a mix...$Msg = GUIGetMsg () If $Msg <> 0 Then _Event ($Msg)and _event does the switch statement? That way It won't be switching 0 against handles... Or could I register a message insted, would that bring any benefits... 3) Whats better, 1 big array, or lots of smaller variables? Thanks MDiesel Edited May 28, 2009 by mdiesel AutoIt Project Listing
Vert Posted May 28, 2009 Posted May 28, 2009 Here are a few questions I have been meaning to ask about the efficiency of a script. 1) Is it more efficient to have lots of variables, or lots of functions? Right now I have 50 lines of declaring global variables for my programs defaults. Would it be better to simply call iniread every time I need it? I am presuming mathod 2 will mean a lower cpu when not in use, but 1 will give a lower cpu when in use?? 2) I know its an old debate, but which is more efficient, GUIGetMsg or set on event? Or could I do a mix...$Msg = GUIGetMsg () If $Msg <> 0 Then _Event ($Msg)and _event does the switch statement? That way It won't be switching 0 against handles... Or could I register a message insted, would that bring any benefits... 3) Whats better, 1 big array, or lots of smaller variables? Thanks MDiesel 1) You won't really notice a difference in most cases regardless, but on technical terms, it would be more efficient to use the declared variables as you stated. 2) Not sure about this one. 3) What do you mean by "better"? Arrays are good for "lists" of objects, whereas standard variables are meant for "single" objects. It's good practice to use the most appropriate of the two at a given time, but it's hard to slap a "BETTER" label on one of the two.
Moderators Melba23 Posted May 28, 2009 Moderators Posted May 28, 2009 mdiesel,Purely personal opinions:1. 50 lines of globals is a lot - particularly if you have several per line. I try to have as few as possible and pass parameters where possible. Some variables have to be Global in scope or you end up passing huge numbers of parameters. If you do need lots of parameters, you can use arrays or, as I have been doing lately, a Dictionary object - which lets you have descriptive key names to refer to variables rather than just index numbers. Look at aGorilla's Hash.au3 here.2. As you have pointed out, there are pros and cons for both GUI modes. I tend to use GUIGetMsg in the main script loop, but TrayOnEventMode for the tray menu. For me the main reason to use GUIGetMsg is being able to pass parameters - although using martin's UDF here can get over this.3. If the numerous variables have some form of common thread, then I would go for an array - if they are totally independent then I would leave them as such. The problem of remembering which index refers to which variable outweighs any gain in typing time! If you want to pass large numbers of them as parameters - see my comment on Dictionary objects above.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Mat Posted May 28, 2009 Author Posted May 28, 2009 Thank you both, My variables are all settings, so I will probably have $aSet_[x] and have a reference for myself somewhere... Or use the dictionaryy object, I am testing that now, and it looks like something I can really use! As for 2, I think I have reached a conclusion. $Msg = GUIGetMsg () If $Msg = 0 Then Continueloop Switch $Msg One more thing, how much more efficient is object orientated scripting? MDiesel AutoIt Project Listing
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