Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CLOCKS_PER_SEC ? just curious

37 views
Skip to first unread message

G G

unread,
Jun 18, 2019, 7:21:02 PM6/18/19
to
how does this value get set or assigned being that
compilers and cpu and clock cycles can be different
depending on the cpu, clock cycles... is it somehow
assigned or read and calculated from the bios or uefi.

ctime / time.h header files

James Kuyper

unread,
Jun 18, 2019, 8:05:31 PM6/18/19
to
CLOCKS_PER_SEC is a macro "which expands to an expression with type
clock_t" (7.27.1p2). That description allows for the possibility that it
expands into a function call, which might do any of the things you're
talking about.

Keith Thompson

unread,
Jun 18, 2019, 10:01:23 PM6/18/19
to
The CLOCKS_PER_SEC macro yields the precision of the value returned
by the clock() function. It doesn't *necessarily* correspond to
any physical characteristic of the system. An imaginary example:
if CLOCKS_PER_SEC is one million (as it is on POSIX systems),
the value returned by clock() represents a number of microseconds,
but it might always be a multiple of 1000, indicating an underlying
resolution of 1 millisecond.

As James Kuyper points out, the standard's definition of
CLOCKS_PER_SEC allows it to vary (though presumably it would keep the
same value for a run of a program), but on many (most?) systems it's
defined as a constant. In fact, I'd be at least mildly surprised
if there were a system with CLOCKS_PER_SEC not defined as a constant.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Juha Nieminen

unread,
Jun 19, 2019, 6:37:23 AM6/19/19
to
G G <gdo...@gmail.com> wrote:
> how does this value get set or assigned being that
> compilers and cpu and clock cycles can be different
> depending on the cpu, clock cycles... is it somehow
> assigned or read and calculated from the bios or uefi.

Even if CLOCKS_PER_SEC is, for example, 1000, that doesn't mean you
are going to get the timing at 1ms of accuracy. The values may well
jump by more than 1.

That value only indicates what you need to divide std::clock() by
in order to get seconds. It doesn't indicate what the accuracy
of that function is. (It may well be more or less accurate than
that.) Internally, whatever the system uses will get scaled
so that the multiplier will be CLOCKS_PER_SEC.

Manfred

unread,
Jun 22, 2019, 1:54:19 PM6/22/19
to
In other words, CLOCKS_PER_SEC is more coupled to the implementation of
clock() rather than to properties of the specific CPU etc.
0 new messages