[TI BASIC] Optimizing

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
digiTsai
New Member
Posts: 13
Joined: Wed 30 Mar, 2005 12:48 am
Location: SC, USA

Post by digiTsai »

crap i had to register :(
O well, at least there wasn't an activation email


You could try factoring, though I do not know if it will be faster

Code: Select all

X+7(Ans=26)-7(Ans=24->X 
to

Code: Select all

X+7((Ans=26)-(Ans=24->X 
There are a few places you could factor at.


Virtuoso
MooK
New Member
Posts: 61
Joined: Sat 12 Mar, 2005 1:58 pm

Post by MooK »

prgmPerson (at this moment) is only called when a key is pressed. (It is an image of the sprite facing towards the user. I hope to animate it, but I have not yet gotten there, so maybe I will put it in the program for now. Thanks
I am not sure about the factoring, but I will try it, thanks.
digiTsai
New Member
Posts: 13
Joined: Wed 30 Mar, 2005 12:48 am
Location: SC, USA

Post by digiTsai »

Code: Select all

If Ans>86 or Ans<0:Then
Ans+7(Ans<=1)-7(Ans>=87->X
End 
Why do you have a Then and an End there?
MooK
New Member
Posts: 61
Joined: Sat 12 Mar, 2005 1:58 pm

Post by MooK »

I was told that when one uses If:Then End instead of If:Then that the execution is faster. Well, someone actually tested it, and for my program (where that if evaluates to false most of the time) it is faster.
digiTsai
New Member
Posts: 13
Joined: Wed 30 Mar, 2005 12:48 am
Location: SC, USA

Post by digiTsai »

I found another one

instead of

Code: Select all

While 1
If Ans
Then
commands
End
End
Do this:

Code: Select all

While 1
If not(Ans
End
commands
End
MooK
New Member
Posts: 61
Joined: Sat 12 Mar, 2005 1:58 pm

Post by MooK »

Ok lemme try that one out.
Seems faster :D Thanks
MooK
New Member
Posts: 61
Joined: Sat 12 Mar, 2005 1:58 pm

Post by MooK »

Hmmm....is
Getkey:Ans->A
faster than
Getkey->A
?
digiTsai
New Member
Posts: 13
Joined: Wed 30 Mar, 2005 12:48 am
Location: SC, USA

Post by digiTsai »

I dunno if this will be faster. It does bring it down by 1 byte though (2 if you do it for the "y" also)

Code: Select all

X+7(Ans=26)-7(Ans=24->X
If Ans>86 or Ans<0:Then
Ans+7(Ans<=1)-7(Ans>=87->X
End 
To

Code: Select all

X+7(Ans=26)-7(Ans=24
If Ans>86 or Ans<0:Then
Ans+7(Ans<=1)-7(Ans>=87
End
Ans->X
MooK
New Member
Posts: 61
Joined: Sat 12 Mar, 2005 1:58 pm

Post by MooK »

I am guessing that that might slow it down. I just tested the getkey thing I was wondering about...The first method (getkey->A) is 1.36 times faster, so going by that I think the new thing would slow the program down a little. I will remember that though, because I might optimize it for size later on, thanks.
digiTsai
New Member
Posts: 13
Joined: Wed 30 Mar, 2005 12:48 am
Location: SC, USA

Post by digiTsai »

How do you test the speed of your programs?
DarkerLine
Calc Wizard
Posts: 526
Joined: Tue 08 Mar, 2005 1:37 am
Location: who wants to know?
Contact:

Post by DarkerLine »

Say you want to test if randInt(0,10 or int(11rand is faster. You make the following program:

Code: Select all

For(I,1,2000
randInt(0,10
End
Pause "randInt( DONE
For(I,1,2000
int(11rand
End
"int(rand DONE
then you dig out a stopwatch and time it.
just try to be nice to people.
_________________
My TI Blog - http://mpl.unitedti.org/
MooK
New Member
Posts: 61
Joined: Sat 12 Mar, 2005 1:58 pm

Post by MooK »

That is what I did with the getkey, but for the others I tired to time the speed of the sprite moving across the screen...heh...bad move. I think I will go back and test everything again...
MooK
New Member
Posts: 61
Joined: Sat 12 Mar, 2005 1:58 pm

Post by MooK »

...Wait a second. I just inputed
:If 0<X<86:Then
Blah Blah Blah



Does that actually work?



*edit* Oh yeah, I just tested
If X>86 or X<0:X+7(X<=1)-7(X>=87->X
Vs
X+7(X<=1)-7(X>=87->X

The latter wins. Then I did this
If X>86 or X<0:Then
X+7(X<=1)-7(X>=87->X
End
Vs
X+7(X<=1)-7(X>=87->X
Again the latter one wins :shock: But it was closer this time.

I am not sure how to test ...Any suggestions?

Code: Select all

While 1
If Ans
Then
commands
End
End
VS

Code: Select all

While 1
If not(Ans
End
commands
End
merthsoft
Extreme Poster
Posts: 496
Joined: Tue 21 Dec, 2004 6:49 am
Location: WI

Post by merthsoft »

...Wait a second. I just inputed
:If 0<X<86:Then
Blah Blah Blah



Does that actually work?
Wholy crap, it does...
Shaun
digiTsai
New Member
Posts: 13
Joined: Wed 30 Mar, 2005 12:48 am
Location: SC, USA

Post by digiTsai »

I think it does this
(0<X)<86

So if it is greater than 0, then the 0<X will be the value 1

Im not sure though
Post Reply