I have an unoptimized phone number saver that stores string data and phone number data to a list, then recalls it later for number browsing. Problem is, It is SLOW since it reads each list entry, stores it to the next variable on the string for both Name and number (2 lists), which takes about a minute, then finally displays the information. Any ideas on how to optimize for speed? I know that RPG games usually store map data to a list or matrix. How do they retrieve the data quickly?
you could have it read the info from the list and then dirrectly display it, instead of storing it to a string first (I think that's what you're doing..)
OK, here's the list reader which is what takes so long (its a sub program)
:32(A)-31->C ""->Str4 ""->Str5 1->L For(B,C,C+15 Output(o,p,ipart(((L/16)*100)/2 ∟PHONE(B)->T prgmθθRCLLST \\JUST A GIANT IF...THEN BLOCK that tells what number or letter a number in If not(length(Str4 \\ the data list means. Any suggestions on how to replace this with something smaller and faster? Str2->Str4 If length(Str4 Str4+Str2->Str4 1+L->L End For(B,C+16,C+31 Output(O,P,ipart(((L/16)*100)/2 \\ this is a percent done indicator, displayed at O,P ∟PHONE(B)->T prgmθθRCLLST If not(length(Str5 Str2->Str5 If length(Str5 Str5+Str2->Str5 1+L->L End sub(Str4,2,16->Str4 sub(Str5,2,16->Str5 Now for the sub program, I wont type the whole thing, just parts, so you get the idea. (T is the number stored on the data list) If T=1 "A"->Str2 If T=2 "B"->Str2 If T=3 "C"->Str2 ... ... If T=26 "Z"->Str2 If T=27 "_"->Str2 If T=28 "--"->Str2 If T=29 "1"->Str2 If T=30 "2"->Str2 ... ... If T=37 "9"->Str2 If T=38 "0"->Str2 Return BTW, the first program is a sub program called from within the main program to "remember" the contact names and numbers., after it finishes, then it displays the info. I would like it to take 3 sec at most if possible. Both the Name and the Number are I think exactly 15 characters long, maybe it was 16.
Ok, here's my optimization:
:32A-31→C :"→Str4 \\I removed the ending quote, as it is not necessary :"→Str5 \\alternatively, you could use Ans, but it's doesn't make a big difference :1→L :For(F,0,16,16 \\you don't have to use F, use whatever variable you want :For(B,C+F,C+(F+15 :Output(O,P,iPart(E2(L/32 \\scientific E :∟PHONE(B→T :prgmθθRCLLST :If not(F:Then :If not(length(Str4 :Str2→Str4 :If length(Str4 :Str4+Str2→Str4 :End :If F:Then :If not(length(Str5 :Str2→Str5 :If length(Str5 :Str5+Str2→Str5 :End :1+L→L :End :End :sub(Str4,2,16→Str4 :sub(Str5,2,16→Str5
This can probably be optimized even more, if anyone is up for it.
For the subprogram, here's some optimizations:
If T=1 "A"->Str2 If T=2 "B"->Str2 If T=3 "C"->Str2 ... ... If T=26 "Z"->Str2 can be :If T≥1 and T≤26 :sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",T,1→Str2
and instead of
you could use a number to string routine, however I am not sure if it would be faster or not. anyways, there are 2 different routines to choose from, so you could do either this one or this one. Your choice :)
I'm guessing that storing the numbers into Str2 is necessary, but if it's not absolutely necessary, you could obviously just do
:If T≥29 and T≤38
even if you have to change around some of your other code to make that work(if it's possible), it would definitely be faster than doing a number to string routine or the code that you had. If you can't make it work, a number to string routine or your code would still do just fine.
Just extend the string in the sub( so it covers all the way up to T=38…
However, at T=27, there is "_"->Str2 (which I'm guessing just stands for 1 space?). And at T=28, there is "- -"→Str2.
Of course, this is pretty easy to solve. The ENTIRE subprogram can be optimized to this:
:sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890",T,1→Str2 :If T=28:"--→Str2
I don't even know why you would need a subprogram anymore though, so I would just include this in the main program :)