|
|||||
|
|||||
Created on: July 8, 1997
|
Sieripinski's Triangle is a very famous fractal that is shown in the image on the left. The image is made by a simple technique. See the program's Events Editor. A random position on the screen is selected and then a random number is repeatedly picked, thousands of repetitions are needed. Based on the results of the random number one of three functions are applied to the X and Y coordinates of the Draw Tool. This simple process is all it takes to make the design you see. If you run the program will immediately notice one thing; it is SLOW. The question is what can one do to improve the programs performance. This where optimization techniques come in. | |
Download File |
If you will examine the program, you will find that it contains these apparently unnecessary items: a Clock object, an INI object, and a Counter object. But if you look a little closer you will discover that the three object allow me to time how long it takes for the program to perform a certain number of iterations, I believe it counts to a thousand. After a thousand loops it saves the time information to an INI file called time and ends the program. While the program is running the Clock object and the Counter object display the elapsed time and the number of loops respectively. This allows one to get an idea of the results while the program is running.
We now have a way of determining how long the program takes to do one thousand loops. However, that alone will never make the program any faster. Now the fun starts. Now we get to experiment. Now we change something and see if that speeds up the program or slows down the program. And either way we have learned something, which we will be able to apply again in the future. So not only is this program better, but all of our programs from now on will be a little better. And we will be better programmers too.
At first, you might want to change the number of loops to be counted to, to something a little smaller like 100. This way every time you do something you want have to wait ten minutes to learn the results.
Now you might be asking what do I change?
Here are something to consider:
The program uses floating-point calculations extensively. I made a this program in Klik & Play originally so I know that it could be done using integers which would improve the performance a little each loop which would add up exponentially over a thousand loops.
The program does not have to use the Draw object. Remember Klik & Play did not have a Draw object. Active object could be created instead. In Klik & Play the triangle was made using about 256 dots and was completely unrecognizable. In Click & Create I used the Paste into Background feature and was able to get much better results. Now you have to wonder which way is faster using the Draw object or using the Active object?
I used the Draw object Line Tool to draw the dots. I could have the Point Tools. Why did I use the Draw object instead? Are you curious? There is only one way to find out because I am not going to tell you. Beyond that, I could have used some of the other tools. A very small circle looks for all the world to be a dot.
And I'm sure you have a few ideas of your own you want to look into to.
The Optimization Challenge:
The challenge is to make a more optimized version of this program. Whoever makes the most optimized version of this program will have their name listed below.
Currently the winner of the Optimization Challenge is: Chris Craft
Come on, you are not just going to let my name sit there when you could have your there, are you? Shame on you. Just give it a try you might surprise yourself with how much better you can do. Besides, it has been a while since I have been put in my place.
I'm Hoping that that this will encourage some of you all to participate. Good luck.