Jump to content

a question of power.


Recommended Posts

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 by mdiesel
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...