[nhc-bugs] Portability issue in CPUTime.cpuTimePrecision

Wolfgang Lux wlux@uni-muenster.de
Mon, 8 Sep 2003 10:53:07 +0200


Hello!

I just discovered a minor bug in the implementation of the module 
CPUTime
in nhc 1.16. The function cpuTimePrecision returns the fixed constant
1000000, i.e., it assumes that the resolution of the (C) function 
clock(3)
is always 1us. While this is true for systems that conform to the Single
Unix Spec (including at least Linux, Solaris, and AIX according to my 
quick
tests), it is wrong for BSD derived OS'es. At least for Mac OS X, 
FreeBSD,
and NetBSD, the resolution of the clock function is only 10ms.

In order to make this function portable, cpuTimePrecision should return 
the
value
   1000000000000{-this should be 10^12-} `div` CLOCKS_PER_SEC
where the value of CLOCKS_PER_SEC is defined in <time.h> (or some file
included from there).

Regards
Wolfgang