News:

;) This forum is the property of Proton software developers

Main Menu

Which is faster, if/then, select/case or Les's macro.

Started by RGV250, Apr 13, 2023, 09:36 AM

Previous topic - Next topic

RGV250

Hi,
I have a number (0 - 15) which I need to write to 4 pins on a port. The other pins are used so I cannot just say Portx = VarXYZ.
I have looked a Les example here https://protoncompiler.com/index.php/topic,1570.0.html which seems overkill. I could do a lot of if/then statements but Select case seems to be the neatest solution. My concern is in the manual it describes select case as an advanced form of if/then. I am assuming that this means more code overhead and therefore slower.

Bob

top204

The Select-EndSelect, is just a different format for If-Then-Else statements. So for code times, they are the same for standard comparisons. But Select-EndSelect is faster if performing its Or or Between comparisons because it only needs to look at a single variable for its comparisons. i.e. The one in the Select statement.

If you are just loading the variable with a constant value, then the meta-macros are much faster, because they will simply set or clear bits using a single mnemonic for each bit. However, if loading the variable with another variable's contents, then masking is the better method, because there are not multiple comparisons of a variable before a particular bit pattern is found and loaded into the assignment variable.

Masking and bit loading with a meta-macro also keeps the times the same for any bit pattern being loaded, whereas a group of comparisons will alter the time it takes, depending on where the particular pattern is found in the comparisons.