The Sieve Client

The sieve of Eratosthenes Client program in Figure 10-1 counts prime numbers. The obvious purpose of this application is to tell you how many prime numbers there are up to a given maximum, and to list them. If you check the Display box, the program will do exactly that. But in reality, this is the least important purpose of the sieve.

Figure 10-1. The sieve of Eratosthenes Client.

The real purpose is to compare the performance of the same algorithm in as many formats as possible. That’s why the client program has functional versus object-oriented, early-bound versus late-bound, Basic versus C++, and getting all the primes at once versus getting one at a time. We don’t really care about the prime numbers, only about how long it takes to calculate them in different environments.

You’ll usually want to calculate all primes up to a given number several times to get useful values. If you’re simply testing speed, you can throw away the results but you do need a display mode to prove that the numbers you’re calculating are really primes. The timing is useless with the display on, however, because you’re timing more display than calculation.

Simply writing the fastest possible algorithm would be an unrealistic test of ActiveX components. A server has to serve something, so you should at least pretend that the user of your class really needs the data. So let’s say that prime numbers are very useful in calculating proportional radial intensity vectors of the newly discovered subatomic particles called quinks. To properly serve the powerful programs searching the universe for quinks, you need an ActiveX component that hands over prime numbers.