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