Search in sources :

Example 6 with Timer

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

the class MessageFormatsPerfTest method testParameterizedPerf.

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

Example 7 with Timer

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

the class MessageFormatsPerfTest method testStringPerf.

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

Example 8 with Timer

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

the class ThreadedPerfTest method debugDisabled.

@Test
public void debugDisabled() {
    final Timer timer = new Timer("DebugDisabled", LOOP_CNT * THREADS);
    final Runnable runnable = new DebugDisabledRunnable();
    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 9 with Timer

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

the class SimplePerfTest method debugLogger.

@Test
public void debugLogger() {
    System.gc();
    final Timer timer = new Timer("DebugLogger", LOOP_CNT);
    final String msg = "This is a test";
    timer.start();
    for (int i = 0; i < LOOP_CNT; ++i) {
        logger.debug(msg);
    }
    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 10 with Timer

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

the class MessageFormatsPerfTest method testMessageFormatPerf.

@Test
public void testMessageFormatPerf() {
    final String testMsg = "Test message {0} {1}";
    final Timer timer = new Timer("MessageFormat", LOOP_CNT);
    timer.start();
    for (int i = 0; i < LOOP_CNT; ++i) {
        final MessageFormatMessage msg = new MessageFormatMessage(testMsg, "Apache", "Log4j");
        array[i] = msg.getFormattedMessage();
    }
    timer.stop();
    msgFormatTime = 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