mirror of
https://github.com/cc65/cc65.git
synced 2025-02-21 05:29:16 +00:00
Time the execution
git-svn-id: svn://svn.cc65.org/cc65/trunk@784 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
f063c4e844
commit
0bb81e5c36
@ -4,7 +4,10 @@
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <conio.h>
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user