Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <vc8fa1$2m1lh$1@dont-email.me>
Deutsch   English   Français   Italiano  
<vc8fa1$2m1lh$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Paul <nospam@needed.invalid>
Newsgroups: alt.comp.lang.c,comp.lang.c
Subject: Re: A very slow program
Date: Mon, 16 Sep 2024 01:22:09 -0400
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <vc8fa1$2m1lh$1@dont-email.me>
References: <vc7nb0$7rl3$1@paganini.bofh.team>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 16 Sep 2024 07:22:10 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="479e6ac3209ef72c496fbd8aafdf2846";
	logging-data="2819761"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18KoQdq8QVRfl1PolGI1XDehAHSsD1loQg="
User-Agent: Ratcatcher/2.0.0.25 (Windows/20130802)
Cancel-Lock: sha1:VBdQFHban3Kz2u7hF8ZzueRVBPg=
Content-Language: en-US
In-Reply-To: <vc7nb0$7rl3$1@paganini.bofh.team>
Bytes: 2270

On Sun, 9/15/2024 6:45 PM, Student Project wrote:
> #include <time.h>
> #include <stdio.h>
> 
> #define RUNS 1000
> #define SIZE 1000000
> 
> int mark[SIZE];
> 
> int main(void)
> {
>      time_t start, finish;
>      int i, loop, n, num;
> 
>      time(&start);
> 
>      /*  This loop finds the prime numbers between 2 and SIZE   */
>      for (loop = 0; loop < RUNS; ++loop)
>      {
>          for (n = 0; n < SIZE; ++n)
>              mark[n] = 0;
>          /*  This loops marks all the composite numbers with -1  */
>          for (num = 0, n = 2; n < SIZE; ++n)
>              if (!mark[n])
>              {
>                  for (i = 2 * n; i < SIZE; i += n)
>                      mark[i] = -1;
>                  ++num;
>              }
>      }
>      time(&finish);
>      printf("Program takes an average of %f seconds "
>             "to find %d primes.\n",
>             difftime(finish, start) / RUNS, num);
> }
> /*
> The result on my slow machine:
> Program takes an average of 0.018000 seconds to find 78498 primes.
> */
> 

Good prime code, comes with its own timing routines :-)

http://cr.yp.to/primegen.html

   http://cr.yp.to/primegen/primegen-0.97.tar.gz

  Paul