sysctl with KERN_BOOTTIME option vs. gettimeofday()

Mari Kotlov mkotlov at gmail.com
Tue Mar 17 08:49:27 PDT 2009


Hi everyone,
I am doing a port of C++ code from Windows to FreeBSD and need to
replace function GetTickCount(), which is used mostly for the purposes
of obtaining elapsed time (e.g. as a millisecond timer). As I
understand it, there are two ways to do that: 1) via sysctl() function
with CTL_KERN&KERN_BOOTTIME options and 2) via gettimeofday(). In both
case, struct timeval is returned, so I can compute the difference
between the two times and get the elapsed time.

I am wondering if anyone could tell me performance implications of
using sysctl() function call to obtain system boot time vs.
gettimeofday(). Is one better than the other? More efficient? Are
there advantages or disadvantages to using either of these two
methods? Any insight would be appreciated.

Thanks very much in advance,
Mari.


More information about the freebsd-performance mailing list