From 2ec5b3fb2ccb0120be641e077089f3da5e53d8a3 Mon Sep 17 00:00:00 2001 From: xleroy Date: Sun, 17 Sep 2006 12:04:56 +0000 Subject: Davantage de tests git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@104 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- test/c/nsievebits.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/c/nsievebits.c (limited to 'test/c/nsievebits.c') diff --git a/test/c/nsievebits.c b/test/c/nsievebits.c new file mode 100644 index 00000000..ad96011d --- /dev/null +++ b/test/c/nsievebits.c @@ -0,0 +1,77 @@ +/* + * The Great Computer Language Shootout + * http://shootout.alioth.debian.org/ + * + * Written by Dima Dorfman, 2004 + * Compile: gcc -std=c99 -O2 -o nsieve_bits_gcc nsieve_bits.c + */ + +#include +#include +#include + +typedef unsigned int bits; +#define NBITS (8 * sizeof(bits)) + +static unsigned long +nsieve(unsigned long m) +{ + unsigned long count, i, j; + bits * a; + a = malloc((m / NBITS) * sizeof(bits)); + memset(a, (1 << 8) - 1, (m / NBITS) * sizeof(bits)); + count = 0; + for (i = 2; i < m; ++i) + if (a[i / NBITS] & (1 << i % NBITS)) { + for (j = i + i; j < m; j += i) + a[j / NBITS] &= ~(1 << j % NBITS); + ++count; + } + return (count); +} + +static void +test(unsigned long n) +{ + unsigned long count, m; + + m = (1 << n) * 10000; + count = nsieve(m); + printf("Primes up to %8ju %8ju\n", m, count); +} + +int +main(int ac, char **av) +{ + unsigned long n; + char *cp; + + n = ac < 2 ? 9 : strtoul(av[1], &cp, 10); + test(n); + if (n >= 1) + test(n - 1); + if (n >= 2) + test(n - 2); + exit(0); +} +/**** + build & benchmark results + +BUILD COMMANDS FOR: nsievebits.gcc + +Fri Sep 15 06:30:15 PDT 2006 + +/usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -funroll-loops -march=pentium4 nsievebits.c -o nsievebits.gcc_run + +================================================================= +COMMAND LINE (%A is single numeric argument): + +nsievebits.gcc_run %A + + +PROGRAM OUTPUT +============== +Primes up to 5120000 356244 +Primes up to 2560000 187134 +Primes up to 1280000 98610 +*****/ -- cgit