A very slow program

Liste des GroupesRevenir à cl c 
Sujet : A very slow program
De : student (at) *nospam* invalid.invalid (Student Project)
Groupes : alt.comp.lang.c  comp.lang.c
Date : 16. Sep 2024, 00:45:59
Autres entêtes
Organisation : To protect and to server
Message-ID : <vc7nb0$7rl3$1@paganini.bofh.team>
#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.
*/


Date Sujet#  Auteur
16 Sep 24 * A very slow program21Student Project
16 Sep 24 +- Re: A very slow program1Kaz Kylheku
16 Sep 24 +* Re: A very slow program3Paul
2 Oct 24 i`* Re: A very slow program2Vir Campestris
2 Oct 24 i `- Re: A very slow program1Paul
2 Oct 24 +* Re: A very slow program14Bonita Montero
3 Oct 24 i+* OT: Re: A very slow program12Vir Campestris
4 Oct 24 ii`* Re: OT: Re: A very slow program11Bonita Montero
20 Oct 24 ii `* Re: OT: Re: A very slow program10Vir Campestris
20 Oct 24 ii  +* Re: OT: Re: A very slow program2Kenny McCormack
26 Oct 24 ii  i`- Re: OT: Re: A very slow program1Vir Campestris
21 Oct 24 ii  +* Re: OT: Re: A very slow program6Bonita Montero
26 Oct 24 ii  i`* Re: OT: Re: A very slow program5Vir Campestris
26 Oct 24 ii  i `* Re: OT: Re: A very slow program4Bonita Montero
26 Oct 24 ii  i  `* Re: OT: Re: A very slow program3Vir Campestris
27 Oct 24 ii  i   `* Re: OT: Re: A very slow program2Bonita Montero
28 Oct 24 ii  i    `- Re: OT: Re: A very slow program1Vir Campestris
22 Oct 24 ii  `- Re: OT: Re: A very slow program1Richard Harnden
3 Oct 24 i`- Re: A very slow program1Paul
2 Oct 24 `* Re: A very slow program2Janis Papanagnou
3 Oct 24  `- Re: A very slow program1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal