1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.issue.lbcore243;
15
16 import org.apache.log4j.xml.DOMConfigurator;
17
18 import ch.qos.logback.core.joran.spi.JoranException;
19
20
21
22
23 public class PerformanceComparatorLog4j {
24
25 static org.apache.log4j.Logger log4jlogger = org.apache.log4j.Logger.getLogger(PerformanceComparatorLog4j.class);
26
27 public static void main(String[] args) throws JoranException, InterruptedException {
28 initLog4jWithoutImmediateFlush();
29
30
31 log4jDirectDebugCall();
32
33 System.out.println("###############################################");
34 System.out.println("Log4j without immediate flush: " + log4jDirectDebugCall() + " nanos per call");
35 System.out.println("###############################################");
36 }
37
38 private static long log4jDirectDebugCall() {
39 Integer j = Integer.valueOf(2);
40 long start = System.nanoTime();
41 for (int i = 0; i < Common.loop; i++) {
42 log4jlogger.debug("SEE IF THIS IS LOGGED " + j + ".");
43 }
44 return (System.nanoTime() - start) / Common.loop;
45 }
46
47 static String DIR_PREFIX = "src/test/java/ch/qos/logback/classic/issue/lbcore243/";
48
49 static void initLog4jWithoutImmediateFlush() {
50 DOMConfigurator.configure(DIR_PREFIX + "log4j_without_immediateFlush.xml");
51 }
52
53 static void initLog4jWithImmediateFlush() {
54 DOMConfigurator.configure(DIR_PREFIX + "log4j_with_immediateFlush.xml");
55 }
56 }