could someone help me optimize this program for speed please? More things I add, the more it slows down and I'm pretty sure there's probably something I could do more efficiently. Any help is appreciated Good Idea .
It'd really help if you could share your source code through Source Coder rather than your Archive download. Meanwhile, does this guide on optimization help? My best guess is that it's slowing down because of memory leaks, make sure to avoid those like the plague.
TheLastMillennial wrote:
It'd really help if you could share your source code through Source Coder rather than your Archive download. Meanwhile, does this guide on optimization help? My best guess is that it's slowing down because of memory leaks, make sure to avoid those like the plague.

sure, the source code for the 3rd level (by far the slowest) is here:
if you're wondering why there's a help at the bottom with nothing going to it, I completely forgot to add that into the pause menu. It would be next to resume (just added it btw)

Code:
ClrHome
0→P
3→S
3→T
7→Y
9→X
1→C
0→Q
randInt(5,21→E
randInt(2,9→D
randInt(5,21→G
randInt(2,9→F
randInt(2,9→O
randInt(4,23→P
Lbl θ
"888→Str0
Lbl A
Output(1,5,"SCORE:
Output(1,12,Q
Output(4,6,"π
Output(2,9,"π
Output(1,14,Str0+Str0+Str0+"8
Output(10,1,Str0+Str0+Str0+Str0+Str0+Str0+Str0+Str0+"88
Output(1,1,Str0
Output(2,1,Str0
Output(3,1,Str0
Output(4,1,Str0
Output(5,1,Str0
Output(6,1,Str0
Output(7,1,Str0
Output(8,1,Str0
Output(9,1,Str0
Output(1,24,Str0
Output(2,24,Str0
Output(3,24,Str0
Output(4,24,Str0
Output(5,24,Str0
Output(6,24,Str0
Output(7,24,Str0
Output(8,24,Str0
Output(9,24,Str0
Lbl W
While 1
Output(8,4,"9
Output(2,23,"9
Output(5,8,"F
Output(6,8,"F
Output(5,7,"F
Output(6,7,"F
Output(1,12,Q
Output(Y,X,"θ
Output(D,E,"X
Output(F,G,"X
Output(O,P,"X
Output(6,23,"O
Output(7,10,"W
O→H
O+1→O
If O=10
Then
2→O
End
Output(O,P,"X
Output(H,P,"
G→U
G+1→G
If G=23
Then
4→G
End
Output(F,G,"X
Output(F,U,"
getKey→C
If C=24
Then
X→T
X-1→X
Output(Y,T,"
End
If C=26
Then
X→T
X+1→X
Output(Y,T,"
End
If C=25
Then
Y→S
Y-1→Y
Output(S,X,"
End
If C=34
Then
Y→S
Y+1→Y
Output(S,X,"
End
If Y=8 and X=4
Then
2→Y
23→X
End
If X=24
Then
23→X
End
If X=3
Then
4→X
End
If Y=10
Then
2→Y
End
If Y=1
Then
9→Y
End
If D=Y and E=X
Then
Goto Z
End
If F=Y and G=X
Then
Goto Z
End
If X=23 and Y=6 and Q=2
Then
ClrHome
Disp "LEVEL 4 COMING SOON!
Pause "PRESS [ENTER]
Return:Goto B
prgmLOFDLVL2
End
If X=10 and Y=7
Then
S→Y
T→X
End
If X=6 and Y=4 and Q=0
Then
1→Q
Output(4,6,"
End
If X=9 and Y=2 and Q=1
Then
2→Q
Output(2,9,"
Else
Output(2,9,"π
End

If C=45
Then
Menu("Paused","Resume",W,"Help",C,"Quit",B
End
End
ClrHome
Lbl C
ClrHome
Output(1,1,"MOVE: ARROW KEYS
Output(2,1,"YOU: θ
Output(3,1,"ENEMIES: X
Output(4,1,"WALLS: W
Output(5,1,"POINTS: π
Output(6,1,"TARGET: O
Output(7,1,"OTHER STUFF: F,B, and D
Pause
ClrHome
Goto W
Lbl Z
If Q>Z
Then
Output(1,1,"NEW BEST!
Output(1,11,Q
End
prgmPROG03
Goto θ
Lbl B
ClrHome

And for the special level I just made

Code:
ClrHome
0→P
6→S
9→T
6→Y
9→X
1→C
0→Q
4→A
7→B
randInt(5,21→E
randInt(2,9→D
randInt(5,21→G
randInt(2,9→F
randInt(2,9→O
randInt(4,23→P
Lbl θ
"888→Str0
Lbl A
Output(1,5,"SCORE:
Output(1,12,Q
Output(4,6,"π
Output(2,9,"π
Output(1,14,Str0+Str0+Str0+"8
Output(10,1,Str0+Str0+Str0+Str0+Str0+Str0+Str0+Str0+"88
Output(1,1,Str0
Output(2,1,Str0
Output(3,1,Str0
Output(4,1,Str0
Output(5,1,Str0
Output(6,1,Str0
Output(7,1,Str0
Output(8,1,Str0
Output(9,1,Str0
Output(1,24,Str0
Output(2,24,Str0
Output(3,24,Str0
Output(4,24,Str0
Output(5,24,Str0
Output(6,24,Str0
Output(7,24,Str0
Output(8,24,Str0
Output(9,24,Str0
Lbl W
While 1
Output(8,4,"9
Output(2,23,"9
Output(5,8,"F
Output(6,8,"F
Output(5,7,"F
Output(6,7,"F
Output(1,12,Q
Output(Y,X,"θ
Output(D,E,"X
Output(F,G,"X
Output(O,P,"X
Output(B,A,"X
Output(6,23,"O
Output(7,10,"W
Output(8,10,"W
Output(9,10,"W
Output(7,9,"W
O→H
B→U
A→V
B+1→B
A+1→A
If A=23
Then
4→A
End
If B=10
Then
2→B
End
Output(B,A,"X
Output(U,V,"
O+1→O
If O=10
Then
2→O
End
Output(O,P,"X
Output(H,P,"
G→U
G+1→G
If G=23
Then
4→G
End
Output(F,G,"X
Output(F,U,"
getKey→C
If C=24
Then
X→T
X-1→X
Output(Y,T,"
End
If C=26
Then
X→T
X+1→X
Output(Y,T,"
End
If C=25
Then
Y→S
Y-1→Y
Output(S,X,"
End
If C=34
Then
Y→S
Y+1→Y
Output(S,X,"
End
If Y=8 and X=4
Then
2→Y
23→X
End
If X=24
Then
23→X
End
If X=3
Then
4→X
End
If Y=10
Then
2→Y
End
If Y=1
Then
9→Y
End
If D=Y and E=X
Then
Goto Z
End
If F=Y and G=X
Then
Goto Z
End
If B=Y and A=X
Then
Goto Z
End
If O=Y and P=X
Then
Goto Z
End
If X=23 and Y=6 and Q=2
Then
ClrHome
prgmADVTLVL3
Disp "LEVEL 4 COMING SOON!
Pause "PRESS [ENTER]
Return:Goto B
prgmLOFDLVL2
End
If X=10 and Y=7
Then
S→Y
T→X
End
If X=10 and Y=8
Then
S→Y
T→X
End
If X=10 and Y=9
Then
S→Y
T→X
End
If X=9 and Y=7
Then
S→Y
T→X
End
If X=6 and Y=4 and Q=0
Then
1→Q
Output(4,6,"
End
If X=9 and Y=2 and Q=1
Then
2→Q
Output(2,9,"
End
If X=9 and Y=2 and Q≠2
Then
Output(2,9,"π
End

If C=45
Then
Menu("PAUSED","RESUME",W,"HELP",C,"QUIT",B
End
End
ClrHome
Lbl C
ClrHome
Output(1,1,"MOVE: ARROW KEYS
Output(2,1,"YOU: θ
Output(3,1,"ENEMIES: X
Output(4,1,"WALLS: W
Output(5,1,"POINTS: π
Output(6,1,"TARGET: O
Output(7,1,"OTHER STUFF: F,B, and D
Pause
ClrHome
Goto θ
Lbl Z
If Q>Z
Then
Output(1,1,"NEW BEST!
Output(1,11,Q
End
prgmPROG03
Goto θ
Lbl B
ClrHome
Loops, my friend. Loops are the answer!
The code snippet:

Code:
Output(1,1,Str0
Output(2,1,Str0
Output(3,1,Str0
Output(4,1,Str0
Output(5,1,Str0
Output(6,1,Str0
Output(7,1,Str0
Output(8,1,Str0
Output(9,1,Str0
Output(1,24,Str0
Output(2,24,Str0
Output(3,24,Str0
Output(4,24,Str0
Output(5,24,Str0
Output(6,24,Str0
Output(7,24,Str0
Output(8,24,Str0
Output(9,24,Str0

Can become the much shorter by looping over the rows where the strings are displayed:

Code:
For(A,1,9
Output(A,1,Str0
Output(A,24,Str0
End

You can do similar optimizations for other repeated Output( statements.
Many of your If statements can be simplified because they only have one command in them; this:

Code:
If X=24
Then
23→X
End

can become

Code:
If X=24:23→X

This optimization can't be done for If statements with more than one command contingent upon them; those can be probably improved by simplifying the overall logic.
I also noticed a potential memory leak in your code; this is a situation where the program exits some form of control flow (a loop or If statement, for example) before reaching an End statement. Specifically:

Code:
If D=Y and E=X
Then
Goto Z
End

presents a memory leak because of the Goto; this can be avoided using the If statement trick I showed earlier:

Code:
If D=Y and E=X:Goto Z

Memory leaks can be avoided by generally avoiding the use of Goto statements, or at the very least only using them to move between more disconnected sections of the program.
Finally, and this is a higher-level technique, the randInt( statements can be simplified a bit using the sequential equations u, v, and w, which essentially store expressions to be executed later. These random integers assignments:

Code:
randInt(5,21→E
randInt(2,9→D
randInt(5,21→G
randInt(2,9→F
randInt(2,9→O
randInt(4,23→P

can be turned into

Code:
"randInt(5,21→u
"randInt(2,9→v
u→E:u→G
v→D:v→F:v→O
randInt(4,23→P

Hope this helps!
Also,
"0→<letter variable>" can be "DelVar <letter variable>", provided it is not in Archive.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement