diff --git a/samples/sieve.c b/samples/sieve.c index 24e5601cb..e04fc6fca 100644 --- a/samples/sieve.c +++ b/samples/sieve.c @@ -4,7 +4,10 @@ +#include #include +#include +#include #include @@ -30,11 +33,17 @@ static unsigned char Sieve[COUNT]; int main (void) { + /* Clock variable */ + clock_t Ticks; + /* This is an example where register variables make sense */ register unsigned char* S; register unsigned I; register unsigned J; + /* Read the clock */ + Ticks = clock(); + /* Execute the sieve */ I = 2; while (I < SQRT_COUNT) { @@ -50,17 +59,27 @@ int main (void) ++I; } + /* Calculate the time used */ + Ticks = clock() - Ticks; + + /* Print the time used and wait for a key */ + printf ("Time used: %lu ticks\n", Ticks); + printf ("Press Q to quit, any other key for list\n"); + if (toupper (cgetc()) == 'Q') { + exit (EXIT_SUCCESS); + } + /* Print the result */ for (I = 2; I < COUNT; ++I) { if (Sieve[I] == 0) { printf ("%4d\n", I); } - if (kbhit() && cgetc() == 'q') { + if (kbhit() && toupper (cgetc()) == 'q') { break; } } - return 0; + return EXIT_SUCCESS; }