Sujet : Re: A very slow program
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : alt.comp.lang.c comp.lang.cDate : 16. Sep 2024, 03: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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca