-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathRetreivalOfExistingLoggerSpeed.java
98 lines (86 loc) · 3.09 KB
/
RetreivalOfExistingLoggerSpeed.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2022, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.classic;
import java.io.IOException;
import org.apache.log4j.Hierarchy;
import org.apache.log4j.spi.RootLogger;
import ch.qos.logback.classic.HLoggerContext;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.control.ControlLoggerContext;
import ch.qos.logback.classic.control.CreateLogger;
import ch.qos.logback.classic.control.Scenario;
import ch.qos.logback.classic.control.ScenarioMaker;
public class RetreivalOfExistingLoggerSpeed {
static final LoggerContext listLoggerContext = new LoggerContext();
static final HLoggerContext hashLoggerContext = new HLoggerContext();
static final ControlLoggerContext controlContext = new ControlLoggerContext();
static final Hierarchy log4jHierarchy = new Hierarchy(new RootLogger(org.apache.log4j.Level.OFF));
static String X;
public static void main(String[] args) throws IOException {
Scenario s = ScenarioMaker.makeTypeBScenario(2000);
X = ((CreateLogger) s.get(1000)).getLoggerName();
System.out.println("name:"+X);
System.err.print("Press a key to continue: ");
System.in.read();
int x1 = 100000;
for (int i = 0; i < 1; i++) {
x1 *= 2;
getLoggerSpeed(x1);
//getHLoggerSpeed(x1);
getLog4jLoggerSpeed(x1);
getContolLoggerSpeed(x1);
getJULSpeed(x1);
}
}
static void getLoggerSpeed(final int len) {
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
listLoggerContext.getLogger(X);
}
long result = System.nanoTime() - start;
System.out.println(("Logger ") + (result / len));
}
static void getHLoggerSpeed(final int len) {
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
hashLoggerContext.getLogger(X);
}
long result = System.nanoTime() - start;
System.out.println(("HLogger ") + (result / len));
}
static void getContolLoggerSpeed(final int len) {
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
controlContext.getLogger(X);
}
long result = System.nanoTime() - start;
System.out.println(("ControlLogger ") + (result / len));
}
static void getJULSpeed(final int len) {
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
java.util.logging.Logger.getLogger(X);
}
long result = System.nanoTime() - start;
System.out.println(("JUL ") + (result / len));
}
static void getLog4jLoggerSpeed(final int len) {
long start = System.nanoTime();
for (int i = 0; i < len; i++) {
log4jHierarchy.getLogger(X);
}
long result = System.nanoTime() - start;
System.out.println(("Log4j Logger ") + (result / len));
}
}