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: Thu, 13 Oct 2016 11:29:17 -0700 Organization: None to speak of Lines: 32 Message-ID: References: <44h98g5iii.fsf@be-well.ilk.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="2f0e64d192bea43a8327a03587074a79"; logging-data="28779"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IaMEBgWvwsuiJErng1nTs" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:meJc6B1P/LmACp4JLd2zuKAQOqA= sha1:YqPGQocIAQSIJrUQTC3lUyBgdrY= Xref: csiph.com comp.lang.c:94837 Lowell Gilbert writes: > Keith Thompson writes: >> BartC writes: >>> 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 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.) >> >> Write a C function that returns the value of the macro, and call that >> function from the foreign language. Depending on your build system, you >> can probably do this at configuration time rather than at run time. > > Or write a wrapper that returns the equivalent in nanoseconds. Assuming that 1/CLOCKS_PER_SEC is a whole number of nanoseconds. (I don't object to making the assumption, I'm just pointing out that it is one.) -- 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"