Page 1 of 1

Is it faster to place user def functions at the beginning of the code ?

Posted: Thu Mar 10, 2016 11:58 pm
by smabasgil
I once read in a BASIC documentation that it was to locate SUB routines at the beginning of the code, since when the interpreter searches for a ref, it always starts at the beginning, and then is more likely to find the ref quicker.
Does the code in SB obeys to this behavior ? Then do i need to place DEF - ENDDEFs at the beginning of the code ? And the ones more called at the very top ?

Re: Is it faster to place user def functions at the beginning of the code ?

Posted: Fri Mar 11, 2016 4:05 am
by Mr. Kibernetik
No, for sB there is no difference where DEF is placed.

Re: Is it faster to place user def functions at the beginning of the code ?

Posted: Fri Mar 11, 2016 5:06 am
by Operator
Any other tips:hints to "squeze" smart Basis
concerning speed...?
- would short variable names help?
- would avoiding use of struct.variables
in main loops help ?

- For example using sprites only with
no graphics command at all (not even
graphics clear) makes the code fast...

Re: Is it faster to place user def functions at the beginning of the code ?

Posted: Fri Mar 11, 2016 7:31 am
by Mr. Kibernetik
There is no difference what names are used. Also there is no difference whether scope variables are used or not.

Sprites may work faster than main graphics screen because sprite is a small graphics screen, and main graphics screen is much bigger in size.

sB is tuned internally to work fast. Before running it performs code checking and finds all labels and DEFs, so when running it already knows where they are located - that is why it does not matter where they are placed in program.