-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.c
56 lines (47 loc) · 1.1 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "primes.h"
long currentTimeMillis() {
clock_t t1;
t1 = clock();
return t1 / 1000;
}
long measure(int prntCnt, int upto) {
NaturalType n;
initNatural(&n);
PrimesType primes;
initPrimes(&primes, &n);
long start = currentTimeMillis();
int cnt = 0;
int res = -1;
for (;;) {
res = nextPrime(&primes);
cnt++;
if (cnt % prntCnt == 0) {
printf("Computed %d primes in %ld ms. Last one is %d\n", cnt, (currentTimeMillis() - start), res);
prntCnt *= 2;
}
if (upto && cnt >= upto) {
break;
}
}
releasePrimes(&primes);
return currentTimeMillis() - start;
}
int main(int argc, char** argv) {
int count = -1;
if (argc == 2) {
count = atoi(argv[1]);
}
for (;;) {
printf("Hundred thousand prime numbers in %ld ms\n", measure(97, 100000));
if (count != -1) {
if (--count == 0) {
break;
}
}
}
return (EXIT_SUCCESS);
}