001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.issue.lbcore243;
015
016import org.apache.log4j.xml.DOMConfigurator;
017
018import ch.qos.logback.core.joran.spi.JoranException;
019
020// WARNING This code compiles but does not measure anything useful because log4j-over-slf4j is a dependency. Log4j
021// should be used instead
022
023public class PerformanceComparatorLog4j {
024
025    static org.apache.log4j.Logger log4jlogger = org.apache.log4j.Logger.getLogger(PerformanceComparatorLog4j.class);
026
027    public static void main(String[] args) throws JoranException, InterruptedException {
028        initLog4jWithoutImmediateFlush();
029
030        // Let's run once for Just In Time compiler
031        log4jDirectDebugCall();
032
033        System.out.println("###############################################");
034        System.out.println("Log4j    without immediate flush: " + log4jDirectDebugCall() + " nanos per call");
035        System.out.println("###############################################");
036    }
037
038    private static long log4jDirectDebugCall() {
039        Integer j = Integer.valueOf(2);
040        long start = System.nanoTime();
041        for (int i = 0; i < Common.loop; i++) {
042            log4jlogger.debug("SEE IF THIS IS LOGGED " + j + ".");
043        }
044        return (System.nanoTime() - start) / Common.loop;
045    }
046
047    static String DIR_PREFIX = "src/test/java/ch/qos/logback/classic/issue/lbcore243/";
048
049    static void initLog4jWithoutImmediateFlush() {
050        DOMConfigurator.configure(DIR_PREFIX + "log4j_without_immediateFlush.xml");
051    }
052
053    static void initLog4jWithImmediateFlush() {
054        DOMConfigurator.configure(DIR_PREFIX + "log4j_with_immediateFlush.xml");
055    }
056}