From f83c208b82c78dad07f4065f63bdd354f5ef9951 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 12 Sep 2014 16:33:37 -0700 Subject: [PATCH] Explain why clock(3) isn't broken. Bug: 17441123 Change-Id: I6ee9b7f54bab55b1a8760ce9bcaaa6eab1dcc492 --- libc/bionic/clock.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/bionic/clock.cpp b/libc/bionic/clock.cpp index 98f71afc3..a2636c67c 100644 --- a/libc/bionic/clock.cpp +++ b/libc/bionic/clock.cpp @@ -34,5 +34,8 @@ clock_t clock() { tms t; times(&t); + // Although times(2) and clock(3) both use the type clock_t, the units are + // different. For times(2) it's pure clock ticks, but for clock(3) the unit + // is CLOCKS_PER_SEC, so we need to scale appropriately. return (t.tms_utime + t.tms_stime) * (CLOCKS_PER_SEC / sysconf(_SC_CLK_TCK)); }