1   package org.slf4j.impl;
2   
3   import junit.framework.TestCase;
4   
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   
8   public class PerfTest extends TestCase {
9   
10    public PerfTest(String name) {
11      super(name);
12    }
13  
14    protected void setUp() throws Exception {
15      super.setUp();
16    }
17  
18    protected void tearDown() throws Exception {
19      super.tearDown();
20    }
21  
22    public void testBug72() {
23      Logger logger = LoggerFactory.getLogger(PerfTest.class);
24      int len = 2000;
25      for (int i = 0; i < len; i++) {
26        logger.debug("hello");
27      }
28      
29      long start = System.currentTimeMillis();
30      for (int i = 0; i < len; i++) {
31        logger.debug("hello");
32      }
33  
34      long end = System.currentTimeMillis();
35      
36      long duration = end-start;
37      // when the code is guarded by a logger.isLoggable condition, 
38      // duration is about 16 *micro*seconds for 1000 iterations
39      // when it is not guarded the figure is 90 milliseconds,
40      // i.e a ration of 1 to 5000
41      assertTrue(duration <= 5);
42    }
43  
44  }