You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/08/03 22:28:56 UTC
svn commit: r1615450 -
/logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/Log4jLogEventBenchmark.java
Author: mattsicker
Date: Sun Aug 3 20:28:56 2014
New Revision: 1615450
URL: http://svn.apache.org/r1615450
Log:
Add more Log4jLogEvent benchmarks.
Modified:
logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/Log4jLogEventBenchmark.java
Modified: logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/Log4jLogEventBenchmark.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/Log4jLogEventBenchmark.java?rev=1615450&r1=1615449&r2=1615450&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/Log4jLogEventBenchmark.java (original)
+++ logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/Log4jLogEventBenchmark.java Sun Aug 3 20:28:56 2014
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.perf.jmh;
import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.SimpleMessage;
@@ -26,6 +27,8 @@ import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.logic.BlackHole;
+import java.io.Serializable;
+
@State(Scope.Thread)
public class Log4jLogEventBenchmark {
private static Message MESSAGE;
@@ -49,12 +52,55 @@ public class Log4jLogEventBenchmark {
}
@GenerateMicroBenchmark
+ public void testNoExceptionUsingBuilder(final BlackHole bh) {
+ final LogEvent event = Log4jLogEvent.newBuilder()
+ .setLoggerName("a.b.c")
+ .setLoggerFqcn("a.b.c")
+ .setLevel(Level.INFO)
+ .setMessage(MESSAGE)
+ .build();
+ bh.consume(event);
+ }
+
+ @GenerateMicroBenchmark
public void testException(final BlackHole bh) {
- final Throwable t = ERROR;
- final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, t);
+ final LogEvent event = Log4jLogEvent.newBuilder()
+ .setLoggerName("a.b.c")
+ .setLoggerFqcn("a.b.c")
+ .setLevel(Level.INFO)
+ .setMessage(MESSAGE)
+ .setThrown(ERROR)
+ .build();
bh.consume(event);
}
+ @GenerateMicroBenchmark
+ public void testSourceLocation(final BlackHole bh) {
+ final LogEvent event = Log4jLogEvent.newBuilder()
+ .setLoggerName(this.getClass().getName())
+ .setLoggerFqcn(this.getClass().getName())
+ .setLevel(Level.INFO)
+ .setMessage(MESSAGE)
+ .build();
+ event.setIncludeLocation(true);
+ final StackTraceElement source = event.getSource();
+ bh.consume(source);
+ }
+
+ @GenerateMicroBenchmark
+ public void testSerializationWithoutException(final BlackHole bh) {
+ final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, null);
+ final Serializable serializable = Log4jLogEvent.serialize(event, false);
+ bh.consume(serializable);
+ }
+
+ @GenerateMicroBenchmark
+ public void testSerializationWithException(final BlackHole bh) {
+ final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, ERROR);
+ final Serializable serializable = Log4jLogEvent.serialize(event, false);
+ bh.consume(serializable);
+ }
+
// ============================== HOW TO RUN THIS TEST: ====================================
//
// In sampling mode (latency test):