| Deutsch English Français Italiano |
|
<20240915193738.293@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: alt.comp.lang.c,comp.lang.c Subject: Re: A very slow program Date: Mon, 16 Sep 2024 02:44:10 -0000 (UTC) Organization: A noiseless patient Spider Lines: 24 Message-ID: <20240915193738.293@kylheku.com> References: <vc7nb0$7rl3$1@paganini.bofh.team> Injection-Date: Mon, 16 Sep 2024 04:44:10 +0200 (CEST) Injection-Info: dont-email.me; posting-host="5717e2d929ec0698218a2d4babcc74c0"; logging-data="2760591"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mKc5irGHnNIj7jciMlUFCTZ5gYUwdAkk=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:PvKaKoNM32WgplZamx5Jt1v78Zw= Bytes: 1874 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