Search in sources :

Example 1 with Timer

use of org.apache.logging.log4j.Timer in project logging-log4j2 by apache.

the class SimplePerfTest method debugDisabledByLevel.

@Test
public void debugDisabledByLevel() {
    System.gc();
    final Timer timer = new Timer("DebugDisabled", LOOP_CNT);
    timer.start();
    for (int i = 0; i < LOOP_CNT; ++i) {
        logger.isEnabled(Level.DEBUG);
    }
    timer.stop();
    System.out.println(timer.toString());
    assertTrue("Timer exceeded max time of " + maxTime, maxTime > timer.getElapsedNanoTime());
}
Also used : Timer(org.apache.logging.log4j.Timer) Test(org.junit.Test)

Example 2 with Timer

use of org.apache.logging.log4j.Timer in project logging-log4j2 by apache.

the class SimplePerfTest method setupClass.

@BeforeClass
public static void setupClass() {
    final Configuration config = LoggerContext.getContext().getConfiguration();
    if (!DefaultConfiguration.DEFAULT_NAME.equals(config.getName())) {
        System.out.println("Configuration was " + config.getName());
        LoggerContext.getContext().start(new DefaultConfiguration());
    }
    for (int i = 0; i < WARMUP; ++i) {
        overhead();
    }
    System.gc();
    final Timer timer = new Timer("Setup", LOOP_CNT);
    timer.start();
    for (int i = 0; i < (LOOP_CNT / 150); ++i) {
        overhead();
    }
    timer.stop();
    maxTime = timer.getElapsedNanoTime();
    System.gc();
    System.out.println(timer.toString());
}
Also used : DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) Timer(org.apache.logging.log4j.Timer) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) BeforeClass(org.junit.BeforeClass)

Example 3 with Timer

use of org.apache.logging.log4j.Timer in project logging-log4j2 by apache.

the class SimplePerfTest method debugDisabled.

@Test
public void debugDisabled() {
    System.gc();
    final Timer timer = new Timer("DebugDisabled", LOOP_CNT);
    timer.start();
    for (int i = 0; i < LOOP_CNT; ++i) {
        logger.isDebugEnabled();
    }
    timer.stop();
    System.out.println(timer.toString());
    assertTrue("Timer exceeded max time of " + maxTime, maxTime > timer.getElapsedNanoTime());
}
Also used : Timer(org.apache.logging.log4j.Timer) Test(org.junit.Test)

Example 4 with Timer

use of org.apache.logging.log4j.Timer in project logging-log4j2 by apache.

the class ThreadedPerfTest method debugLogger.

@Test
public void debugLogger() {
    final Timer timer = new Timer("DebugLogger", LOOP_CNT * THREADS);
    final Runnable runnable = new DebugLoggerRunnable();
    final ExecutorService pool = Executors.newFixedThreadPool(THREADS);
    timer.start();
    for (int i = 0; i < THREADS; ++i) {
        pool.execute(runnable);
    }
    pool.shutdown();
    timer.stop();
    System.out.println(timer.toString());
}
Also used : Timer(org.apache.logging.log4j.Timer) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 5 with Timer

use of org.apache.logging.log4j.Timer in project logging-log4j2 by apache.

the class MessageFormatsPerfTest method testFormattedParameterizedPerf.

@Test
public void testFormattedParameterizedPerf() {
    final String testMsg = "Test message {} {}";
    final Timer timer = new Timer("FormattedParameterized", LOOP_CNT);
    timer.start();
    for (int i = 0; i < LOOP_CNT; ++i) {
        final FormattedMessage msg = new FormattedMessage(testMsg, "Apache", "Log4j");
        array[i] = msg.getFormattedMessage();
    }
    timer.stop();
    formattedTime = timer.getElapsedNanoTime();
    System.out.println(timer.toString());
}
Also used : Timer(org.apache.logging.log4j.Timer) Test(org.junit.Test)

Aggregations

Timer (org.apache.logging.log4j.Timer)10 Test (org.junit.Test)9 ExecutorService (java.util.concurrent.ExecutorService)2 Configuration (org.apache.logging.log4j.core.config.Configuration)1 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)1 BeforeClass (org.junit.BeforeClass)1