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


Groups > comp.lang.c > #94856

Re: CLOCKS_PER_SEC

From Anton Shepelev <anton.txt@g{oogle}mail.com>
Newsgroups comp.lang.c
Subject Re: CLOCKS_PER_SEC
Date 2016-10-14 19:53 +0300
Organization A noiseless patient Spider
Message-ID <20161014195348.b58ccefe064bded596425856@g{oogle}mail.com> (permalink)
References <nto3cm$ps$1@dont-email.me> <20161014162129.223274fe7ba3d5b06850f0e1@g{oogle}mail.com> <lnwphbhran.fsf@kst-u.example.com> <ntqv7f$df$1@jstuckle.eternal-september.org>

Show all headers | View raw


Jerry Stuckle:
>Keith Thompson:
>>Anton Shepelev:
>>>BartC:
>>>
>>>>CLOCKS_PER_SEC  determines how the result of the
>>>>clock() function is interpreted.
>>>>
>>>>But it seems to be defined as macro in time.h.
>>>>
>>>>Any ideas on how to determine  that  value  when
>>>>calling clock() as foreign function from another
>>>>language? I want to avoid OS-specific  functions
>>>>unless  they  are  available on both Windows and
>>>>Linux.
>>>>
>>>>(At the moment, CLOCKS_PER_SEC seems to be  usu-
>>>>ally  1000  on  Windows  and 1000000 on Linux. I
>>>>suppose I could detect abnormally  large  values
>>>>of  clock()  and  infer it that way, but I think
>>>>there will be some overlap in the set  of  valid
>>>>results.)
>>>
>>>Estimate  its value using the native time-measur-
>>>ing functions!  I had to do that in my innovative
>>>snake  game  for  MS-DOS when I wrote it in Turbo
>>>Pascal, whose delay procedure  took  a  value  in
>>>units  the  value whereof depended on the machine
>>>speed, so that every  game  would  start  with  a
>>>time-calibration loop.
>>
>>That  would  be  difficult  to do accurately.  The
>>clock() function measures CPU time, not real time.
>>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.
>
>And don't forget -- modern PC's can adjust CPU fre-
>quency on the fly.  What you get in one calculation
>may  be  much different when repeated.  Things like
>instruction prefetch, bus  contention  on  multiple
>core CPUs can also affect results, although usually
>not as significantly.

Thanks, I now see  that  I  was  wrong.   My  method
worked  in  MS-DOS  but  will not on modern hardware
running modern OSes.

-- 
()  ascii ribbon campaign - against html e-mail
/\  http://preview.tinyurl.com/qcy6mjc [archived]

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