On Jan 21, 2005, at 4:47 PM, Vic wrote:
Thus, instead of writing
if(logger.isDebugEnabled() { logger.debug("New temperature is "+newT+" degrees"); }
you can write
logger.debug("New temperature is {} degrees", newT);
If you can help me understand why are those 2 the same?
The 2nd statment does if somehow? It would not evaluate newT and String concat?
They are not precisely the same, but they are roughly equivalent in performance. When isDebugEnabled() == false, the first form evaluates isDebugEnabled and skips over the log statement avoiding the cost of evaluating "New temperature is "+newT+" degrees".
The second form would call logger.debug(Object, Object), so would incur the cost of a function call regardless of whether debug is enabled, but the implementation of Logger.debug(Object, Object) would check isDebugEnabled() before attempting to expand the template.
So you have:
logger.debug("New temperature is " + newT + "degrees");cost when debug disabled: method call overhead + string concatentation overhead
cost when debug enabled: method call overhead + string concatentation overhead + appender costs
if (logger.isDebugEnabled()) {
logger.debug("New temperature is " + newT + "degrees");
}cost when debug disabled: logger.isDebugEnabled() evaluation + jump
cost when debug enabled: logger.isDebugEnabled() evaluation + method call overhead + string concatentation overhead + appender costs
logger.debug("New temperature is {} degrees", newT)
cost when debug disabled: method call overhead + evaluation of isDebugEnabled() within logger.debug + jump
cost when debug enabled: method call overhead + evaluation of isDebugEnabled() + template expansion + appender costs
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
