2 ** Calculate all primes up to a specific number.
14 /* Workaround missing clock stuff */
17 # define CLOCKS_PER_SEC 1
22 /*****************************************************************************/
24 /*****************************************************************************/
28 #define COUNT 16384 /* Up to what number? */
29 #define SQRT_COUNT 128 /* Sqrt of COUNT */
31 static unsigned char Sieve[COUNT];
35 /*****************************************************************************/
37 /*****************************************************************************/
41 #pragma static-locals(1);
45 static char ReadUpperKey (void)
46 /* Read a key from console, convert to upper case and return */
48 return toupper (cgetc ());
60 /* This is an example where register variables make sense */
61 register unsigned char* S;
66 printf ("Sieve benchmark - calculating primes\n");
67 printf ("between 2 and %u\n", COUNT);
68 printf ("Please wait patiently ...\n");
73 /* Execute the sieve */
75 while (I < SQRT_COUNT) {
77 /* Prime number - mark multiples */
89 /* Calculate the time used */
90 Ticks = clock() - Ticks;
91 Sec = (unsigned) (Ticks / CLOCKS_PER_SEC);
92 Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
94 /* Print the time used */
95 printf ("Time used: %u.%03u seconds\n", Sec, Milli);
96 printf ("Q to quit, any other key for list\n");
98 /* Wait for a key and print the list if not 'Q' */
99 if (ReadUpperKey () != 'Q') {
100 /* Print the result */
102 for (I = 2; I < COUNT; ++I) {
106 printf ("Q to quit, any other key continues\n");
107 if (ReadUpperKey () == 'Q') {
113 if (kbhit() && ReadUpperKey () == 'Q') {