title: Performance issue with logback with slf4j API
body: <p>I am using windows machine to get performance results for logback + slf4j</p>
  
  <pre><code>import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import ch.qos.logback.classic.Level;
  
  public class LogPerformanceAnalyser {
      private static final Logger LOG =
              LoggerFactory.getLogger(LogPerformanceAnalyser.class);
  
      public LogPerformanceAnalyser() {
          ((ch.qos.logback.classic.Logger) LOG).setLevel(Level.ERROR);
      }
  
      public long getTimeWithCheck() {
          long startTime = System.currentTimeMillis();
          for (int i = 0; i &lt; Integer.MAX_VALUE; i++) {
              if (LOG.isDebugEnabled()) {
                  LOG.debug("This log is {} check", "with");
              }
          }
          return System.currentTimeMillis() - startTime;
      }
  
      public long getTimeWithoutCheck() {
          long startTime = System.currentTimeMillis();
          for (int i = 0; i &lt; Integer.MAX_VALUE; i++) {
              LOG.debug("This log is {} check", "without");
          }
          return System.currentTimeMillis() - startTime;
      }
  }
  </code></pre>
  
  <p>Note -
  1. debug is off
  2. Running 10 times to get average result.</p>
  
  <p>Performance Results are :</p>
  
  <pre><code>Total Time getTimeWithoutCheck: 26900 ms
  Total Time getTimeWithCheck : 22536 ms
  </code></pre>
  
  <p>Result is that placing the check before logging saved ~3.5 sec for 21.7 billion logs.</p>
  
  <p>If i changed Logger as non static :</p>
  
  <pre><code>private final Logger LOG = 
          LoggerFactory.getLogger(LogPerformanceAnalyser.class);
  </code></pre>
  
  <p>and I get the following:</p>
  
  <pre><code>Total Time getTimeWithoutCheck: 37095 ms
  Total Time getTimeWithCheck : 47006 ms
  </code></pre>
  
  <p>Can anyone explain the this?</p>