Author |
Topic: Line numbers are slower (Read 555 times) |
|
Monkfish
Full Member
member is offline
Gender:
Posts: 104
|
|
Line numbers are slower
« Thread started 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
|
|
Logged
|
|
|
|
jorgerhv
New Member
member is offline
Posts: 1
|
|
Re: Line numbers are slower
« Reply #1 on: Aug 7th, 2015, 1:01pm » |
|
Would you share the code ? Thanks
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Line numbers are slower
« Reply #2 on: Aug 7th, 2015, 3:37pm » |
|
on Aug 7th, 2015, 1:01pm, jorgerhv wrote:Would you share the code ? |
|
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.
|
|
Logged
|
|
|
|
Monkfish
Full Member
member is offline
Gender:
Posts: 104
|
|
Re: Line numbers are slower
« Reply #3 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?
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline
Gender:
Posts: 210
|
|
Re: Line numbers are slower
« Reply #4 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 )
|
|
Logged
|
|
|
|
Monkfish
Full Member
member is offline
Gender:
Posts: 104
|
|
Re: Line numbers are slower
« Reply #5 on: Aug 7th, 2015, 7:33pm » |
|
Yes, I was sure someone must have written something similar
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Line numbers are slower
« Reply #6 on: Aug 7th, 2015, 7:36pm » |
|
on Aug 7th, 2015, 6:57pm, Monkfish wrote:...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!
Richard.
|
|
Logged
|
|
|
|
|