LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Program from slot to string, but fast

Root / Programming Questions / [.]

a_load_of_barnaclesCreated:
My goal is to get a string from the programming slot, but quicker than I am now. First I tried a very basic technique of going though each in line and adding it to the string like this:
VAR STRING$=""

FOR I=1 TO PRGSIZE(1,0)
 STRING$=STRING$+PRGGET$()
NEXT
This worked fine for smaller programs, but I then I tried it with a bigger program: 3D Parkour Pro, which is 5045 lines long. It took 125 seconds. Since strings slow down when the get big, I tried another tactic:
VAR STRING$=""
DIM H$[1]

FOR I=0 TO PRGSIZE(1,0)
 H$[0]=H$[0]+PRGGET$()
 IF LEN(H$[0])>=10000 THEN UNSHIFT H$,""
NEXT

FOR I=0 TO LEN(H$)
 STRING$=H$[I]+STRING$
NEXT
This worked better, with it clocking in at 109 seconds. I would like it to be under a minute though and have no idea how I can shave off more seconds. Any suggestions would be very helpful. Also I DO NOT want to use built in LOAD or SAVE functions for this, unless they can work on unsaved slots. Thanks! NOTE: Tests done on Old 3DS. If someone could test the speed on a New 3DS that would be very helpful!

Use PUSH STRING$,... INC STRING$,... instead of STRING$=STRING$+... It's a LOT faster since it just modifies the existing string instead of creating a new one.

Ahhh, I'll try this THANK YOU!

It gets it to 108.45 seconds, using both methods: the same as the first second method. Maybe any other ideas? This is an okay speed, It'll do if it has too, but if there is any more suggestions that'd be appreciated.

Maybe store PRGSIZE() in a variable.

Wow, that made it work in about 8 seconds. I am truly baffled. Thank you so much! Final solution:
VAR STRING$="",S=PRGSIZE(1,0)

FOR I=1 TO S
 PUSH STRING$,PRGGET$()
NEXT

Wow, I guess PRGSIZE() is *REALLY* slow then

Wow, I guess PRGSIZE is *REALLY* slow then
The first mode of PRGSIZE returns number of lines in the slot, so one can assume it has to seek every newline character every time you run it. The smart thing would be to cache the result and only recalculate it when the slot has been changed (by PRGINS or something) but eh it's SB.

Wow, I guess PRGSIZE is *REALLY* slow then
I was very surprised when it finished that quickly, I thought the size of the string was the main thing slowing it down. But nope, it was our good friend PRGSIZE.

Also, INC is faster than PUSH when you use it on a string, even though it does the exact same thing.

Also, INC is faster than PUSH when you use it on a string, even though it does the exact same thing.
I'll add that to it as well then. This is great.

MAINCNT just decided to quit I guess, in my test it shows a difference of ten frames when it is clearly a few seconds. Oh well, maybe it stops counting correctly under high loads of something, I don't know.

MAINCNT just decided to quit I guess, in my test it shows a difference of ten frames when it is clearly a few seconds. Oh well, maybe it stops counting correctly under high loads of something, I don't know.
Please use MILLISEC.

MAINCNT just decided to quit I guess, in my test it shows a difference of ten frames when it is clearly a few seconds. Oh well, maybe it stops counting correctly under high loads of something, I don't know.
Please use MILLISEC.
MILLISEC is better, don't know what got into me.

Oh, also, VAR STRING$="" isn't required, strings are initialized to "" automatically. (And why are you VARing some variables but not I?)

Oh, also, VAR STRING$="" isn't required, strings are initialized to "" automatically. (And why are you VARing some variables but not I?)
I just forgot to put in in the code I typed there, I put it in the actual program. And I know they are set to empty strings by default, I just do it that way (probably a side effect from Java haha)