So it wasn’t the best way to do it

Posted: June 27, 2012 in Commodore 64, Programming

After I’ve published the previous post, I was talking to TCD on #awesome BBS chat, and he suggested me use something else to position the cursor:

50000 PRINT LEFT$(“{home}{25 x down}”,y) SPC(x);

And to call the function, I could use:

X=10:Y=10:GOSUB 50000;PRINT “THE STUFF”

My first answer was: “Well, that’s cool but I think my POKEs are faster!“. He then made a good point about the high cost of the string functions I was using. Intrigued, I decide to run some tests comparing both ideas. The benchmark would simply assign 100 random positions to two arrays and print them using both methods. I’d be using the TI command to get the time at the beginning and the end of each function.

The random coordinates were used because my theory was that if the command above has to print, for example, 24 downs and 40 spaces it would take longer than print just few positions from where the cursor would be. On the other hand, the poke commands would go directly to the point!

To my surprise, on the first run, TCD’s method above was twice as fast as the POKE commands from my previous post. String functions fault!.. Right!? Actually wrong… Even passing the X and Y coordinates ready to be used in the function to avoid all string commands, the POKE method was still 50% slower.

That was an interesting discovery for me. Now I’m convinced!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s