[Coco] a couple of programming questions

Wayne Campbell asa.rand at yahoo.com
Sun Nov 22 22:51:12 EST 2009


Oh yes, I almost forgot. String optimization isn't all there is to optimizing code. Should the optimizer try to determine where code optimizations could occur and attempt to optimize?




________________________________
From: Joel Ewy <jcewy at swbell.net>
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Sent: Sun, November 22, 2009 5:24:43 PM
Subject: Re: [Coco] a couple of programming questions

Wayne Campbell wrote:
> Robert
>
> I did the work, and I got results.
> ...
>
> Any string 1 character or larger is a good candidate for optimization. Take " ". This one character is more used in most programs than any other character as a single-character literal. If you DIM a 1-character string, and assign it the value " ", then use it in every place where you used " ", you have added 1 byte to the data storage requirement, and 1 additional reference.
>
> Let's say you have " " 50 times in your code. That's 50x3=150 bytes of code (50 x 9020FF). Dim the string. The assignment adds one reference, so you now have 153 bytes of code, instead of 150, and your data size is 1 byte larger. Why spend the space? Because RunB is going to retrieve that space character from the data memory and display it faster that it will calculate the value of the " " literal, especially if it has to recalculate it 50 times.
>
> In my tests, I broke every string down to its parts and then isolated each different part. There were many like-occurrences, like "Variable" and "Variables", and repeat occurrences, like "Display". Once I had broken everything down, I found that I had many strings that could be put together to form the longer strings. I went the distance and optimized it as much as I could. Was it worth the time it took? Yes. Besides the fact that I see the displays happening more quickly, I also now see better what could be done less intensively, and without detriment to the overall execution speed.
>
>  

Interesting.  How hard would it be to do this programmatically?  i.e. a 
BASIC09 source code optimizer...

JCE

> Wayne
>
>
>
> ________________________________
> From: Robert Gault <robert.gault at worldnet.att.net>
> To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
> Sent: Fri, November 20, 2009 4:54:09 AM
> Subject: Re: [Coco] a couple of programming questions
>
> Wayne Campbell wrote:
>
>  
>> I'm going to test a version of decode with all of the changes/additions to see what it does. I'll report back with some results in the next day or 2.
>>
>> Wayne
>>    
>
> Now you're cooking! Running this test is the only way to tell which version would be optimal or if any differences are even detectable.
>
> In general, a one time use of just about anything in a large program probably won't require optimization. Code that is often used or is an obvious bottleneck is where optimization give good results.
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
>
>
>      
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
>  


--
Coco mailing list
Coco at maltedmedia.com
http://five.pairlist.net/mailman/listinfo/coco



      


More information about the Coco mailing list