Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: CLOCKS_PER_SEC Date: Fri, 14 Oct 2016 08:41:04 -0700 Organization: None to speak of Lines: 36 Message-ID: References: <20161014162129.223274fe7ba3d5b06850f0e1@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="24514"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kqX+JMBtlwbybzHX/chfL" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:RNbcP8QE4z/UeQU7uDnenyXGXiw= sha1:wbJYiSE4nxU/w/gYLvK2bO7mmE8= Xref: csiph.com comp.lang.c:94852 Anton Shepelev writes: > 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 call- >>ing clock() as foreign function from another lan- >>guage? 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 usually >>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-measuring > 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 val- > ue 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. -- Keith Thompson (The_Other_Keith) kst-u@mib.org 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"