Bug 17383 - clock() documentation should say something about the implementation and the accuracy
Summary: clock() documentation should say something about the implementation and the a...
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: manual (show other bugs)
Version: 2.20
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-12 12:01 UTC by Vincent Lefèvre
Modified: 2014-10-10 12:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2014-09-12 12:01:48 UTC
The clock() documentation

  https://www.gnu.org/software/libc/manual/html_node/CPU-Time.html

should say something about the implementation and the accuracy (the code could be better documented too), possibly with official references. This is in relation to bug 12515, about the implementation change. In this bug, it is said: "clock() should provide better precision". However the user doesn't seek improved precision, but improved accuracy: if one gets more digits but the value itself is less accurate (i.e. the error against the ideal value is larger), this is bad. All this depends on the kernel implementation, but I don't know anything about it.

In addition to improved precision, does one also get better accuracy?

I suppose yes, but the answer is not obvious.

Such a documentation is important, as the user may wonder: Should I use clock() or something else?

Note that the clock(3) man page

  http://man7.org/linux/man-pages/man3/clock.3.html

says something about the implementation:

       In glibc 2.17 and earlier, clock() was implemented on top of
       times(2).  For improved precision, since glibc 2.18, it is
       implemented on top of clock_gettime(2) (using the
       CLOCK_PROCESS_CPUTIME_ID clock).

but with the poorly chosen reason "improved precision" instead of "improved accuracy".
Comment 1 Vincent Lefèvre 2014-09-12 12:17:59 UTC
Let's note that with CLOCKS_PER_SEC = 1000000, clock() has a fixed precision of 1 ms. What have changed are:
* the precision of the underlying function;
* as a consequence, the accuracy of the clock() function. But it is still unclear what it actually is.
Comment 2 Vincent Lefèvre 2014-09-12 12:19:11 UTC
(In reply to Vincent Lefèvre from comment #1)
> Let's note that with CLOCKS_PER_SEC = 1000000, clock() has a fixed precision
> of 1 ms.

Sorry, I meant 1 µs.