From ecbbcc1f72ccd2e24124af369c5702bb75ffe86f Mon Sep 17 00:00:00 2001 From: ketrptr Date: Thu, 5 Dec 2024 13:16:27 +0100 Subject: [PATCH] modified: primes/Makefile modified: primes/src/sive.c Changes not staged for commit: deleted: gitignore deleted: primes/Makefile deleted: primes/src/sive.c --- primes/Makefile | 2 +- primes/src/sive.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/primes/Makefile b/primes/Makefile index d8e1eb9..9abeeff 100644 --- a/primes/Makefile +++ b/primes/Makefile @@ -1,5 +1,5 @@ CFALGSD=-Wall -Wextra -g -ggdb -CFALGSF=-Wall -Wextra -Ofast -march=native -mtune=native -funroll-all-loops +CFALGSF=-Wall -Wextra -O3 -march=native -mtune=native -funroll-all-loops CC = gcc fast: src/sive.c diff --git a/primes/src/sive.c b/primes/src/sive.c index 9278af3..33b65c1 100644 --- a/primes/src/sive.c +++ b/primes/src/sive.c @@ -2,6 +2,7 @@ #include #include #include +#include #include typedef uint64_t WORD; @@ -11,14 +12,16 @@ const BOOL true = ~false; // const WORD limit = 542; // const WORD limit = 1e2; -const WORD limit = 1e9; +const WORD limit = 1e8; const WORD nr = 78498; // Sive o Atkins hit wheel const WORD s[] = {1, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59}; const WORD wheelLen = 16; -int main() { +int sieve() { + + clock_t t0 = clock(); BOOL *isPrime = calloc(limit, sizeof(WORD)); assert(isPrime != NULL); @@ -184,6 +187,10 @@ for n² ≤ limit, n ← 60 × w + x where w ∈ {0,1,...}, x ∈ s, n ≥ 7: } printf("\n"); printf("%lu\n", sum); + clock_t t1 = clock(); + clock_t delta = t1 - t0; + printf("clocks: %ld, clocks per sec: %ld, s: %ld ", delta, CLOCKS_PER_SEC, + delta / CLOCKS_PER_SEC); return 0; }