Skip to content

Instantly share code, notes, and snippets.

@hotpaw2
Last active March 15, 2022 19:14
Show Gist options
  • Save hotpaw2/36f1cb005ecf79d94c76 to your computer and use it in GitHub Desktop.
Save hotpaw2/36f1cb005ecf79d94c76 to your computer and use it in GitHub Desktop.
/* sieve.c */
/* An old small benchmark from Byte Magazine, circa 1983 and 1984, thus suitable for that vintage of computer. */
#include <stdio.h>
#define TIMES (100000L)
static unsigned char f[8192];
int main()
{
int i,s,p,k,c,d=0;
long int x1;
s = 8192;
printf("start\n");
for (x1=0;x1<TIMES;x1++) {
c = 0;
for (i=0;i<s;i++) f[i] = 1;
for (i=0;i<s;i++) {
if (f[i] == 1) {
p = i+i+3;
for (k=i;k<s;k+=p) f[k] = 0;
c++;
}
}
d += c;
}
printf("primes found = %d * %ld times = %d\n",c,x1,d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment