[TIB] Re: A TI-83 research question


[Prev][Next][Index][Thread]

[TIB] Re: A TI-83 research question




Arthur J. O'Dwyer wrote:
> 
>   How do the following constructs affect the speed of a
> Basic program on the TI-83 (yes, the "83-")?
> 
> 
>   (1)  While loops as opposed to Repeat loops.
>          I've heard that Repeats are faster, I think,
>          but is this empirically true?

I'd heard that repeat loops were faster as well, but I've never really 
investigated the issue. I think it's all really a matter of what you're 
more used to using when it comes to a choice between the two, as I don't 
believe that the speed difference is all that noticeable.

>   (2)  Breaking out parts of a program into
>        subprograms.
>          In other words, which fragment is faster:
> 
>            prgm:ABCDE           or    prgm:ABCDE
>            :If getKey:Then            :If getKey:Then
>            :*do lots*                 :prgmFGHIJ
>            :*of stuff*                :End
>            :*here*
>            :End                       prgm:FGHIJ
>                                       :*do lots of stuff here*
>                                       :Return

You should definately make sub-programs for situations like that, it 
results in faster code, as well as a loop that's easier to read through. 
Also, it makes editing specific parts of your program easier, as there's 
  less scrolling up and down to do, and all the code there is designed 
for one purpose usually. Sub-programs are a good idea.

> 
>   (3)  Using Lbls with Gotos.
>          I've heard that Goto scans the program for
>          Lbls starting at the top and going down.  Is
>          this empirically true?  Does it matter where in
>          the program file the Goto occurs?
>           Are one- or two-character Lbls significantly
>          better with respect to speed?

I've always made a point to avoid Goto's and Lbl's at all costs, they 
are inherently slow, and can usually be replaced with more efficient 
code.  I've never found there to be much of a difference between speed 
when using 1 or 2 character label names. You can put a Goto just about 
anywhere, but putting one to jump out of an If : Then statement is a 
very bad thing to do. The TI-OS / Basic interpreter on the calc doesn't 
handle that situation well at all.

My advice to you would be to try and just avoid using Goto's and Lbl's, 
they're slower than they're worth.

> I'm especially interested in point (2), since my philosophy
> is to keep the number of program files to a minimum.  Rogue
> has two files, one of which contains a subroutine library
> that looks something like this:
> 
>      prgm:ZROGUE
>      If Ans="DESCMONSTER
>      Goto DM
>      If Ans="DESCOBJECT
>      Goto DO
>      If Ans="TRYMOVE
>      Goto TM
>      Lbl DM
>      name of monster -> Str1
>      Return
>      Lbl DO
>      ...
> 
> Then when I need to print a message, I can call the subroutine:
> 
>      prgm:ROGUE
>      ...
>      "DESCMONSTER
>      prgmZROGUE
>      Disp "THE "+Str1+" HITS!
> 
> It would probably speed up the game to break out the subroutines
> into prgmZDMONST, prgmZDOBJ, prgmZTRYMOVE, and so on, but would the
> annoyance to the player (at having his calc Prgm menu be filled with
> the programmer's subroutines) be worth the speed-up?  That's why I
> want to know about empirical tests of point 2 in particular.

Sub-programs really can help the speed of a program, especially if you 
have large amounts of code under an If statement in your main loop. Try 
making some, I think you'll find that they can be quite useful.

> Thanks,
>  -Arthur







Follow-Ups: References: