Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #94859

Re: CLOCKS_PER_SEC

Path csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: CLOCKS_PER_SEC
Date Fri, 14 Oct 2016 11:14:01 -0700
Organization None to speak of
Lines 38
Message-ID <lnshryiys6.fsf@kst-u.example.com> (permalink)
References <nto3cm$ps$1@dont-email.me> <20161014162129.223274fe7ba3d5b06850f0e1@g{oogle}mail.com> <lnwphbhran.fsf@kst-u.example.com> <20161014185607.e6907b112e1a0dee37bb46a7@g{oogle}mail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="1122fc78d0e2af7d3ccaced5a99dbd59"; logging-data="32660"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sZdQ/Rr+tEUNF4XBce1Eu"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:G5YOuQucvcghtT/KsQYBf4T2/As= sha1:DLpB8z5mzgyy+ElE8FBOtF4ZaQo=
Xref csiph.com comp.lang.c:94859

Show key headers only | View raw


Anton Shepelev <anton.txt@g{oogle}mail.com> writes:
> Keith Thompson:
[...]
>>That  would  be  difficult  to  do accurately.  The
>>clock() function measures CPU time, not real time.
>
> Is it not proportional to real time?

No.  For example, a process waiting on I/O, or swapped out,
consumes little or no CPU time, and on a multicore system a
process can consume more than one CPU second per real-time second.
(Obviously this can be system-specific.)

>>You'd have to execute a loop that consumes a  known
>>amount  of  CPU time and compare that to the values
>>returned by clock() before and after the loop.
>
> Well, I should go the other way round, i.e.  wait  a
> known  length  of  time  and  compare  it  with what
> clock() has counted:
>
>    const Seconds = 10;
>    t1 := clock();
>    native_delay( Seconds );
>    t2 := clock();
>    CLOCKS_PER_SECOND := (t2 - t1) / Seconds;
>
> where native_delay() is whatsoever delay routine the
> host language or OS provides.

The value returned by clock() will probably not advance while
native_delay() is running.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-13 14:49 +0100
  Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 08:57 -0700
    Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 09:07 -0700
      Re: CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-13 23:18 +0100
        Re: CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-13 23:30 +0100
          Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 16:27 -0700
            Re: CLOCKS_PER_SEC raltbos@xs4all.nl (Richard Bos) - 2016-10-16 10:02 +0000
              Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-16 11:32 -0700
    Re: CLOCKS_PER_SEC Lowell Gilbert <lgusenet@be-well.ilk.org> - 2016-10-13 12:19 -0400
      Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 11:29 -0700
        Re: CLOCKS_PER_SEC Lowell Gilbert <lgusenet@be-well.ilk.org> - 2016-10-13 14:39 -0400
          Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 12:03 -0700
        Re: CLOCKS_PER_SEC supercat@casperkitty.com - 2016-10-14 07:47 -0700
  Re: CLOCKS_PER_SEC Anton Shepelev <anton.txt@g{oogle}mail.com> - 2016-10-14 16:21 +0300
    Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-14 08:41 -0700
      Re: CLOCKS_PER_SEC Anton Shepelev <anton.txt@g{oogle}mail.com> - 2016-10-14 18:56 +0300
        Re: CLOCKS_PER_SEC Barry Schwarz <schwarzb@dqel.com> - 2016-10-14 09:49 -0700
        Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-14 11:14 -0700
          Re: CLOCKS_PER_SEC supercat@casperkitty.com - 2016-10-14 11:32 -0700
      Re: CLOCKS_PER_SEC Jerry Stuckle <jstucklex@attglobal.net> - 2016-10-14 11:56 -0400
        Re: CLOCKS_PER_SEC Anton Shepelev <anton.txt@g{oogle}mail.com> - 2016-10-14 19:53 +0300
          Re: CLOCKS_PER_SEC supercat@casperkitty.com - 2016-10-14 09:57 -0700
          Re: CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-14 18:18 +0100
        Re: CLOCKS_PER_SEC Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-10-16 02:55 -0700

csiph-web