LB Booster
General >> General Board >> Line numbers are slower http://lbb.conforums.com/index.cgi?board=general&action=display&num=1438866433 Line numbers are slower
Post by Monkfish on Aug 6th, 2015, 1:07pm
Bad habits die hard and I must admit that I still use line numbers.
Some time ago Richard alluded to the possibility that a long program that used line numbers would probably run slower than one that simply used branch labels.
Well my program has over 1500 lines of code and each one has a line number. Awful I know. So I wrote a short program to strip out the line numbers and replace the branches with labels instead.
I am happy to confirm that my program now runs between 8-10% faster as a consequence.
Now not all programs are so long or time critical, but for those that are, here's another good reason to knock this bad habit on the head
Re: Line numbers are slower
Post by jorgerhv on Aug 7th, 2015, 1:01pm
Would you share the code ? Thanks Re: Line numbers are slower
Post by Richard Russell on Aug 7th, 2015, 3:37pm
Just to clarify, the presence of line numbers doesn't of itself result in a slowing of the program. It's only their use as the destination of a GOTO, GOSUB or RESTORE that is (relatively) slow.
So you can leave the line numbers, if you wish, but adding labels as the destination of branches can speed things up a little.
Richard.
Re: Line numbers are slower
Post by Monkfish on Aug 7th, 2015, 6:57pm
The code to strip out line numbers and replace them with labels? Sure. To use it you have to paste your code to a text file, save the altered version back to a text file and then copy it back into LB or LBB.
...but before I do, are there any instructions other than GOTO GOSUB THEN and ELSE that can be followed by a line number?
Re: Line numbers are slower
Post by tsh73 on Aug 7th, 2015, 7:25pm
I used to use REMLINE.BAS (easily googled) to remove extra line numbers. That is, ones not used as destination.
(again, this will leave exactly only line numbers which slow down LBB )
Re: Line numbers are slower
Post by Monkfish on Aug 7th, 2015, 7:33pm
Yes, I was sure someone must have written something similar
Re: Line numbers are slower
Post by Richard Russell on Aug 7th, 2015, 7:36pm
...but before I do, are there any instructions other than GOTO GOSUB THEN and ELSE that can be followed by a line number?
As I stated in my earlier reply, RESTORE is another. In fact it's the only use of a label which doesn't have a better alternative. GOSUB can be replaced by CALL, event handlers can use SUBs, and GOTO is avoidable altogether by using DO or WHILE. Oh, and ON ERROR GOTO can be replaced by TRY...CATCH!