I've often read on various threads about placing subroutine's (primarily input and main loop) close to the start of a large program to improve speed and have always thought "well how much difference can it make really?"
Well, I've just got my answer in the real world and I question this no more!
I have a 27 line display subroutine which if placed at the end of a 520 line program takes 19 seconds to complete - if I place it at the start of the program it takes just 9 seconds to complete! I'm amazed at the difference! I feel a major rewrite coming on just as an excercise to see how fast I can get the game (it will be compiled anyway eventually).
Just thought this post might be useful to someone like myself who has never written a BASIC game before.
Subroutine placement in BASIC for speed - I'm amazed!
Re: Subroutine placement in BASIC for speed - I'm amazed!
Wow. Way more than I would have thought. That's the kind of saving I'd expect from a RANDOMIZE USR routine. I've wondered this kind of thing before, but never tested it.
For optimised pure BASIC games, Diamond Digger is surprisingly fast for the amount that is happening (granted—it really needs to run at 7MHz). Jim must have used every trick in the book to make it close to playable.
I was going to joke: then you'll need this thread, but I see you started it!I feel a major rewrite coming on just as an excercise to see how fast I can get the game (it will be compiled anyway eventually).
Re: Subroutine placement in BASIC for speed - I'm amazed!
After doing some more testing I'm getting some fluctuating times, I think that my host netbook and the emulator may have a hand in that. Still definitely worth the rewrite though.
I can't get the 128k version of the compiler to work so that isn't an option.
I'm enjoying it all immensely though!
Haha, yes, I'm still a way off that though and now I'm struggling with ram size. I'm hoping that when I finish and get rid of all the REM statements, lose the obsolete code remnants and rename all the memorable variable names to single letters, etc. I'll be able to fit it in the compiler, otherwise I'll have to start thinking about cutting features. The code could probably be massively optimized but unfortunately my brain isn't capable of the mind bending BASIC I often see posted.R-Tape wrote: ↑Sat Mar 02, 2019 10:48 pm I was going to joke: then you'll need this thread, but I see you started it!
I can't get the 128k version of the compiler to work so that isn't an option.
I'm enjoying it all immensely though!