Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Mar 2009 17:52:37 +0100
From:      Pieter de Goeje <pieter@degoeje.nl>
To:        freebsd-performance@freebsd.org
Cc:        Mari Kotlov <mkotlov@gmail.com>
Subject:   Re: sysctl with KERN_BOOTTIME option vs. gettimeofday()
Message-ID:  <200903171752.37337.pieter@degoeje.nl>
In-Reply-To: <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com>
References:  <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday 17 March 2009 16:17:55 Mari Kotlov wrote:
> 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.

For the purpose of determining the elapsed time between two measurements, I 
can recommend clock_gettime(2) w/ CLOCK_MONOTONIC as clock_id.

Sysctl is definately not meant to be used for this, as it is not portable and 
has probably more overhead than clock_gettime() or gettimeofday().

- Pieter



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903171752.37337.pieter>