From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-02-13 10:43:18
On Feb 13, 2008 4:57 AM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> Terence Wilson wrote:
> > One of the most difficult aspects of writing a logging library is not making
> > users' pay for what they don't log. I've noticed that with many logging
> > libraries the inclusion of logging code incurs a run-time penalty of at
> > least one "if" clause per log statement even if we know at compile time that
> > some or all logging is not required. This is a big deal if one wants to
> > liberally sprinkle logging throughout the application.
> > For me, a primary requirement of the logging library is that it is
> > efficient. If that can be done in C++, presumably using templates and
> > compile time tricks to get rid of no-ops, then I'm all for it. I'm guess I'm
> > just not smart enough to figure out how to do that, maybe John is!
> > Efficiency first, features second.
> As a matter of fact, John's library uses an if statement, too. However,
> if the condition is known at compile time the compiler can optimize it
> away perfectly well.
And even if the condition weren't known a compile time, IMHO the
effect wouldn't be measurable anyways, except in the thightest loop of
a program. An extremely predictable branch like that costs practically
zero on modern architectures.