[slf4j-user] is*Enabled vs explicit method call performance measure

coldserenity rmuntyan at softserveinc.com
Fri Aug 19 07:47:48 CEST 2011


Hi,

  The question is not specific to Slf4j, but it is an important part of
slf4j usage.
  Recently in my team we've been arguing which of the 2 methods would work
faster 
            LOG.debug("Some constant string ", obj1, obj2); // method
invocation passing parameters
   OR
            if (LOG.isDebugEnabled()) { // simple method invocation with if
check
                LOG.debug("Some constant string ", obj1, obj2); 
            }

  So I've created a synthetic test (attached in archive 
http://slf4j.42922.n3.nabble.com/file/n3267209/isDebugEnabledPerformanceTest-src.zip
isDebugEnabledPerformanceTest-src.zip ) which produces following strange
results
  Test console output for 50M iterations
        Time to go with direct call: 2ms
        Time to go with if statement: 31ms
  For 500M iterations
        Time to go with direct call: 3ms
        Time to go with if statement: 278ms

  The question is whether there's anything I did wrong in my synthetic test?
Or the results are expected?

  Thanks!
Roman

--
View this message in context: http://slf4j.42922.n3.nabble.com/is-Enabled-vs-explicit-method-call-performance-measure-tp3267209p3267209.html
Sent from the slf4j - user mailing list archive at Nabble.com.


More information about the slf4j-user mailing list