Time the execution
git-svn-id: svn://svn.cc65.org/cc65/trunk@784 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <time.h>
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -30,11 +33,17 @@ static unsigned char Sieve[COUNT];
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
|
/* Clock variable */
|
||||||
|
clock_t Ticks;
|
||||||
|
|
||||||
/* This is an example where register variables make sense */
|
/* This is an example where register variables make sense */
|
||||||
register unsigned char* S;
|
register unsigned char* S;
|
||||||
register unsigned I;
|
register unsigned I;
|
||||||
register unsigned J;
|
register unsigned J;
|
||||||
|
|
||||||
|
/* Read the clock */
|
||||||
|
Ticks = clock();
|
||||||
|
|
||||||
/* Execute the sieve */
|
/* Execute the sieve */
|
||||||
I = 2;
|
I = 2;
|
||||||
while (I < SQRT_COUNT) {
|
while (I < SQRT_COUNT) {
|
||||||
@@ -50,17 +59,27 @@ int main (void)
|
|||||||
++I;
|
++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 */
|
/* Print the result */
|
||||||
for (I = 2; I < COUNT; ++I) {
|
for (I = 2; I < COUNT; ++I) {
|
||||||
if (Sieve[I] == 0) {
|
if (Sieve[I] == 0) {
|
||||||
printf ("%4d\n", I);
|
printf ("%4d\n", I);
|
||||||
}
|
}
|
||||||
if (kbhit() && cgetc() == 'q') {
|
if (kbhit() && toupper (cgetc()) == 'q') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user