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

Post Reply
smabasgil
Posts: 46
Joined: Sat Dec 26, 2015 1:06 pm
My devices: Ipad 2
Flag: Bahamas

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

Post 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 ?

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

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

Post by Mr. Kibernetik »

No, for sB there is no difference where DEF is placed.

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

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

Post 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...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

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

Post 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.

Post Reply