From: cuz Date: Sat, 14 Jul 2001 14:45:04 +0000 (+0000) Subject: Time the execution X-Git-Tag: V2.12.0~2783 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0bb81e5c369bf6f191f6b23d0ae334b7c23b353a;p=cc65 Time the execution git-svn-id: svn://svn.cc65.org/cc65/trunk@784 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- 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; }