if (log.isDebugEnabled()) {
log.debug("Count :" + counter);
}
The performance gain is considerable when not logging at debug. eg. production.
A debug call without check = ~440 nano sec.
A debug call with isDebugEnabled: ~20 nano sec.
The reason is that it is much quicker to check a boolean than create the log string. Without the check, the log string is created anyway and then discarded by the logger when it checks if debug is enabled. The flip side to this is that you incur a 20 nano second overhead when you are logging at debug....but that is a price worth paying for production speed.
Before any smart comments come in about concatenating strings....I agree you should use StringBuilder to create the strings for logs if they contain variables. :)
Tuesday, May 1, 2007
Squeeze every last ounce
If you are looking to optimize your code for speed during production, and I'm assuming you don't log at debug in production, make sure you wrap your debug log outputs with the isDebugEnabled() check.
Labels:
Craftsmanship,
Java
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment