Re: Is there any way to obtain a low-resolution timestamp fast?

Rainer Gerhards <rgerhards@xxxxxxxxxxxxxx> wrote:
Hi all,

I am the developer of rsyslog, a GPLed alternative syslogd found in many

I am in need of a very fast way to obtain a low-resolution timestamp (within
ca one-second resolution), much like time() but faster. I have blogged the
complete problem description:

The only alternative to time I currently see is putting rsyslog to run on a
tick, what I really don't like. I would appreciate any suggestions for
solving this issue.

Some comments about blog:
1) You wrote 4ms, but the math gives 4us (one thoused times faster)
2) On my machine your test program is doing 10^7 calls in 0.931s
3) In the test program atoi is in the inner loop. Moving it
outside loop reduced time for 10^7 operations to 0.481s
that is 0.048us per call. Note that atoi call is comparable
in speed with gettimeofday. In my experience gettimeofday
was faster than printf -- you need really fast convertion
from numerical to textual form if gettimeofday is the
4) If you want to flush buffer at given time why dont you just
set interval timer so that you get signal when you need to
flush buffer? That way you maximize chance for powersaving.
Waldek Hebisch

Relevant Pages