1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.perf.jmh;
18
19 import org.apache.logging.log4j.Level;
20 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
21 import org.apache.logging.log4j.message.Message;
22 import org.apache.logging.log4j.message.SimpleMessage;
23 import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
24 import org.openjdk.jmh.annotations.Scope;
25 import org.openjdk.jmh.annotations.Setup;
26 import org.openjdk.jmh.annotations.State;
27 import org.openjdk.jmh.logic.BlackHole;
28
29 @State(Scope.Thread)
30 public class Log4jLogEventBenchmark {
31 private static Message MESSAGE;
32 private static Throwable ERROR;
33
34 @Setup
35 public void setup() {
36 MESSAGE = new SimpleMessage("Test message");
37 ERROR = new Exception("test");
38 }
39
40 @GenerateMicroBenchmark
41 public void testBaseline(final BlackHole bh) {
42 }
43
44 @GenerateMicroBenchmark
45 public void testNoException(final BlackHole bh) {
46 final Throwable t = null;
47 final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, t);
48 bh.consume(event);
49 }
50
51 @GenerateMicroBenchmark
52 public void testException(final BlackHole bh) {
53 final Throwable t = ERROR;
54 final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, t);
55 bh.consume(event);
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69 }