It would partially depend on your logging level, I assume you had it set below debug so that both would produce the same results?  But I do think something must be wonky with your test, I&#39;d expect at most a 2x performance hit from making 2 calls to the LOG object vs 1 (even though I suspect it would be closer to 1:1 since internally LOG.debug has to call LOG.isDebugEnabled or its equivalent).<br>

<br>With that being said, the time you really want to use isDebugEnabled is when you have more than two parameters, or when one of the parameters requires dereferencing.  In other words you don&#39;t need it for your example of:<br>

<br>LOG.debug(&quot;Some constant string: {} {}&quot;,obj1,obj2);<br><br>But you would need it in any of the following cases:<br><br>if(LOG.isDebugEnabled()) {<br>  LOG.debug(&quot;Lots of Arguments {}, {}, {}, {}&quot;,new Object[] {obj1, obj2, obj3, obj4});  // Since the additional object creation is not necessary when the logging level is below debug<br>

<br>  LOG.debug(&quot;Dereferenced Arguments {}, {}&quot;,obj1.getLastName(),obj1,getFirstName());  // Since unnecessary method calls are performed when the log statement is not written<br><br>  LOG.debug(&quot;Some young noob &quot; + obj1.getExplitive() + &quot;&#39;s up your &quot; + obj1.getPraise() + &quot; code&quot;); // Since building strings from concatenation when is expensive<br>

}<br><br>  (*Chris*)<br><br><br><div class="gmail_quote">On Thu, Aug 18, 2011 at 10:47 PM, coldserenity <span dir="ltr">&lt;<a href="mailto:rmuntyan@softserveinc.com">rmuntyan@softserveinc.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi,<br>
<br>
  The question is not specific to Slf4j, but it is an important part of<br>
slf4j usage.<br>
  Recently in my team we&#39;ve been arguing which of the 2 methods would work<br>
faster<br>
            LOG.debug(&quot;Some constant string &quot;, obj1, obj2); // method<br>
invocation passing parameters<br>
   OR<br>
            if (LOG.isDebugEnabled()) { // simple method invocation with if<br>
check<br>
                LOG.debug(&quot;Some constant string &quot;, obj1, obj2);<br>
            }<br>
<br>
  So I&#39;ve created a synthetic test (attached in archive<br>
<a href="http://slf4j.42922.n3.nabble.com/file/n3267209/isDebugEnabledPerformanceTest-src.zip" target="_blank">http://slf4j.42922.n3.nabble.com/file/n3267209/isDebugEnabledPerformanceTest-src.zip</a><br>
isDebugEnabledPerformanceTest-src.zip ) which produces following strange<br>
results<br>
  Test console output for 50M iterations<br>
        Time to go with direct call: 2ms<br>
        Time to go with if statement: 31ms<br>
  For 500M iterations<br>
        Time to go with direct call: 3ms<br>
        Time to go with if statement: 278ms<br>
<br>
  The question is whether there&#39;s anything I did wrong in my synthetic test?<br>
Or the results are expected?<br>
<br>
  Thanks!<br>
Roman<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://slf4j.42922.n3.nabble.com/is-Enabled-vs-explicit-method-call-performance-measure-tp3267209p3267209.html" target="_blank">http://slf4j.42922.n3.nabble.com/is-Enabled-vs-explicit-method-call-performance-measure-tp3267209p3267209.html</a><br>


Sent from the slf4j - user mailing list archive at Nabble.com.<br>
_______________________________________________<br>
slf4j-user mailing list<br>
<a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a><br>
<a href="http://qos.ch/mailman/listinfo/slf4j-user" target="_blank">http://qos.ch/mailman/listinfo/slf4j-user</a><br>
</font></blockquote></div><br>