Re: A very slow program

Liste des GroupesRevenir à l c 
Sujet : Re: A very slow program
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : alt.comp.lang.c comp.lang.c
Date : 16. Sep 2024, 04:44:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240915193738.293@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-09-15, Student Project <student@invalid.invalid> wrote:
/*
The result on my slow machine:
Program takes an average of 0.018000 seconds to find 78498 primes.
*/

Use the clock() function, to get clock_t time values. They usually
have better granularity than time_t. The resolution of clock_t is
given by the CLOCKS_PER_SEC constant. There is no difftime equivalent;
you just subtract the earlier clock_t from the later one, and divide by
CLOCKS_PER_SEC to get seconds. This is usually done in floating-point:

  clock_t start = clock();
  clock_t end = clock();
  double interval = (end - start) / (double) CLOCKS_PER_SEC;

(This assumes that CLOCKS_PER_SEC is in range of double; if that
were not the case, we get undefined behavior. I'm only pointing this
pointless concern because if I don't, someone else will.)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
16 Sep00:45 * A very slow program3Student Project
16 Sep04:44 +- Re: A very slow program1Kaz Kylheku
16 Sep07:22 `- Re: A very slow program1Paul

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal