[Coco] a couple of programming questions
Wayne Campbell
asa.rand at yahoo.com
Fri Nov 20 02:10:30 EST 2009
Robert Gault wrote:
>Any program using subroutines
This is true, however there are the following considerations. Everything involved in this is together, and will only be executed once. In addition, in Basic09, and while I don't know the exact machine instructions involved, subroutining the code will only add 4 bytes to the code, the GOSUB token and offset integer where the branch occurs, and the RETURN token at the end of the subroutine. Since the code is only executed once, I don't think it will appreciably slow the program as a whole down.
I guess it won't matter where the code is located, unless moving it to the bottom will somehow increase the execution of the rest of the code by its closer proximity to the execution offset.
>This is really the same type of question.
I have been doing some work on string building. I have a number of different strings for display which share words, and a large number of format strings for print using that contain repetitions of the same elements, such as:
"s8>,i5>,s9>,i5>,s11>,i5>,s9>,i5>"
I reduced the elements to separate variables, then used concatenation to build larger segments, and eventually the full format strings.
Between the display strings and format strings, I have created about 200 variables. As decode stands now, without modifying it with these changes, it contains 203 program variables, using 2065 references in the code. I'm not certain that adding 200 more variables, and probably another few-hundred references, is going to speed anything up. The only thing I'm certain about is that each place that has a long or complicated string literal would be replaced with a reference to a single variable. While this seems like it should speed things up, I have to wonder how much time will be spent in initialization building those strings. Then there is the variables themselves. In addition to the increase in data space requirements, all of those 3-byte references are going to add up. I'm not sure if decode will be any smaller, or if it will be larger.
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
________________________________
From: Robert Gault <robert.gault at worldnet.att.net>
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Sent: Thu, November 19, 2009 7:39:56 PM
Subject: Re: [Coco] a couple of programming questions
Wayne Campbell wrote:
> 1. I am dealing with code that is only executed once in the program. It is initialization of variables, initial display, and initial data. Which of the following is better, in terms of overall execution speed of the program?
>
>snip
Any program using subroutines is slower than the same program not using them. Of course, it will also be larger. You will need to decide whether the larger size is more important than a slightly slower speed in the smaller program or if the change in speed is even noticeable.
> 2. I am dealing with string literals of varying lengths. Some of them use the same word or words. Example:
>
This is really the same type of question. Which version uses the least memory and how important is that? Which version is faster and is the difference noticeable? Is the added complexity of concatenation of small strings worth the effort verses any potential decrease in program size?
--
Coco mailing list
Coco at maltedmedia.com
http://five.pairlist.net/mailman/listinfo/coco
More information about the Coco
mailing list