├── .editorconfig
├── .gitattributes
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ └── gradle.yml
├── .gitignore
├── LICENSE
├── README.md
├── benchmark
├── build.gradle
└── src
│ └── main
│ └── java
│ └── io
│ └── goodforgod
│ └── benchmark
│ ├── Log4jLoggerBenchmark.java
│ ├── LoggerBenchmark.java
│ ├── Slf4jLoggerBenchmark.java
│ └── SystemLoggerBenchmark.java
├── build.gradle
├── config
└── codestyle.xml
├── docs
├── setup-1.png
├── setup-2.png
└── setup-3.png
├── goodforgod-simple-logger
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── io
│ │ └── goodforgod
│ │ └── slf4j
│ │ └── Bench.java
│ └── resources
│ └── simplelogger.properties
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── log4j-logger
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── io
│ │ └── goodforgod
│ │ └── log4j
│ │ └── Bench.java
│ └── resources
│ └── log4j2.xml
├── logback-logger
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── io
│ │ └── goodforgod
│ │ └── slf4j
│ │ └── Bench.java
│ └── resources
│ └── logback.xml
├── settings.gradle
├── slf4j-simple-logger
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── io
│ │ └── goodforgod
│ │ └── slf4j
│ │ └── Bench.java
│ └── resources
│ └── simplelogger.properties
└── system-logger
├── build.gradle
└── src
└── main
└── java
└── io
└── goodforgod
└── system
└── Bench.java
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # all-encompassing default settings unless otherwise specified
7 | [*]
8 | end_of_line = lf
9 | charset = utf-8
10 |
11 | # Json
12 | [*.json]
13 | indent_size = 2
14 | indent_style = space
15 | insert_final_newline = false
16 | trim_trailing_whitespace = true
17 |
18 | # Yaml
19 | [{*.yml, *.yaml}]
20 | indent_size = 2
21 | indent_style = space
22 | insert_final_newline = true
23 | trim_trailing_whitespace = true
24 |
25 | # Property files
26 | [*.properties]
27 | indent_size = 2
28 | indent_style = space
29 | insert_final_newline = true
30 | trim_trailing_whitespace = true
31 |
32 | # XML files
33 | [*.xml]
34 | indent_size = 4
35 | indent_style = space
36 | insert_final_newline = true
37 | trim_trailing_whitespace = true
38 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Handle line endings automatically for files detected as text
2 | # and leave all files detected as binary untouched.
3 | * text=auto
4 |
5 |
6 | # The above will handle all files NOT found below
7 | # These files are text and should be normalized (Convert crlf => lf)
8 | *.bash text eol=lf
9 | *.css text diff=css
10 | *.df text
11 | *.htm text diff=html
12 | *.html text diff=html eol=lf
13 | *.java text diff=java eol=lf
14 | *.js text
15 | *.json text eol=lf
16 | *.jsp text eol=lf
17 | *.jspf text eol=lf
18 | *.jspx text eol=lf
19 | *.properties text eol=lf
20 | *.sh text eol=lf
21 | *.tld text
22 | *.txt text eol=lf
23 | *.tag text
24 | *.tagx text
25 | *.xml text
26 | *.yml text eol=lf
27 |
28 |
29 | # These files are binary and should be left untouched
30 | # (binary is a macro for -text -diff)
31 | # Archives
32 | *.7z binary
33 | *.br binary
34 | *.gz binary
35 | *.tar binary
36 | *.zip binary
37 | *.jar binary
38 | *.so binary
39 | *.war binary
40 | *.dll binary
41 |
42 | # Documents
43 | *.pdf binary
44 |
45 | # Images
46 | *.ico binary
47 | *.gif binary
48 | *.jpg binary
49 | *.jpeg binary
50 | *.png binary
51 | *.psd binary
52 | *.webp binary
53 |
54 | # Fonts
55 | *.woff2 binary
56 |
57 | # Other
58 | *.exe binary
59 | *.class binary
60 | *.ear binary
61 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: bug
6 | assignees: GoodforGod
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Additional context**
27 | Add any other context about the problem here.
28 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: enhancement
6 | assignees: GoodforGod
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/gradle.yml:
--------------------------------------------------------------------------------
1 | name: Java CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | paths:
8 | - '**.java'
9 | - '**.gradle'
10 | pull_request:
11 | branches:
12 | - master
13 | - dev
14 |
15 | jobs:
16 | build:
17 | runs-on: ubuntu-latest
18 | strategy:
19 | matrix:
20 | java: [ '17' ]
21 | name: Java ${{ matrix.java }} setup
22 |
23 | steps:
24 | - uses: actions/checkout@v1
25 | - name: Set up JDK
26 | uses: actions/setup-java@v1
27 |
28 | with:
29 | java-version: ${{ matrix.java }}
30 |
31 | - name: Code Style
32 | run: ./gradlew spotlessCheck
33 |
34 | - name: Build
35 | run: ./gradlew shadowJar
36 |
37 | - name: Benchmark [goodforgod-simple-logger]
38 | run: java -jar goodforgod-simple-logger/build/libs/*-all.jar 2>/dev/null
39 |
40 | - name: Benchmark [slf4j-simple-logger]
41 | run: java -jar slf4j-simple-logger/build/libs/*-all.jar 2>/dev/null
42 |
43 | - name: Benchmark [logback-logger]
44 | run: java -jar logback-logger/build/libs/*-all.jar 2>/dev/null
45 |
46 | - name: Benchmark [log4j-logger]
47 | run: java -jar log4j-logger/build/libs/*-all.jar 2>/dev/null
48 |
49 | - name: Benchmark [system-logger]
50 | run: java -jar system-logger/build/libs/*-all.jar 2>/dev/null
51 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Package Files
2 | *.war
3 | *.nar
4 | *.ear
5 | *.zip
6 | *.tar.gz
7 | *.rar
8 |
9 | ### Gradle template
10 | .gradle
11 | build/
12 | target/
13 |
14 | ### Idea generated files
15 | .idea
16 | .settings/
17 | *.iml
18 | out/
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2020 Anton Kurako
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Java Logger Benchmark
2 |
3 | [](https://github.com/GoodforGod/java-logger-benchmark/actions?query=workflow%3A%22Java+CI%22)
4 |
5 | JMH Benchmark for different **synchronous** Java Logger implementations.
6 |
7 | Idea of this benchmark is to put all loggers in the same conditions and measure how they all handle the most common scenarios.
8 | Compare their implementation in such scenarios, some loggers have more flexible configurations, different APIs, some have more features, different implementations.
9 |
10 | At the end it's your choice, do you want flexibility some loggers provide and what are trade-offs of each implementation.
11 |
12 | ## Loggers
13 |
14 | Benchmark features these loggers:
15 | - [io.goodforgod:slf4j-simple-logger:0.13.0](https://github.com/GoodforGod/slf4j-simple-logger)
16 | - [org.slf4j:slf4j-simple:1.7.36](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html)
17 | - [ch.qos.logback:logback-classic:1.2.11](https://logback.qos.ch/)
18 | - [org.apache.logging.log4j:log4j-core:2.17.2](https://logging.apache.org/log4j/2.x/index.html)
19 | - [System.Logger](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) (Java 17)
20 |
21 | ## Benchmark
22 |
23 | Benchmark consists of different common logging scenarios developers typically use in their applications, by the name of the test you can understand what this situation try to emulate, here is full list of tests:
24 | - messageAndStacktrace
25 | - messageWithoutArguments
26 | - messageOneArgumentInTheEnd
27 | - messageOneArgumentInTheMiddle
28 | - messageOneArgumentInTheStart
29 | - messageTwoArgumentInTheEnd
30 | - messageTwoArgumentInTheMiddle
31 | - messageTwoArgumentInTheStart
32 | - messageThreeArgumentInTheEnd
33 | - messageThreeArgumentInTheMiddle
34 | - messageThreeArgumentInTheStart
35 |
36 | Here are corresponding examples of resulted log messages (excluding *messageAndStacktrace* due to big stacktrace):
37 | ```text
38 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - Message is printed for this logger without arguments
39 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - Message is printed for this logger and with the argument: FirstArgument
40 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - Message is printed for FirstArgument argument for this logger
41 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - FirstArgument argument and message is printed for this logger
42 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - Message is printed for this logger and with arguments FirstArgument and SecondArgument
43 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - Message is printed for FirstArgument and SecondArgument argument for this logger
44 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - FirstArgument and SecondArgument arguments and message is printed for this logger
45 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - Message is printed for this logger and with arguments FirstArgument and SecondArgument and ThirdArgument
46 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - Message is printed for FirstArgument and SecondArgument and ThirdArgument argument for this logger
47 | 2022-03-22T15:33:48.723 [INFO] io.goodforgod.benchmark.LoggerBenchmark - FirstArgument and SecondArgument and ThirdArgument argument and message is printed for this logger
48 | ```
49 |
50 | If you want to look at benchmark details, you can [check it here](https://github.com/GoodforGod/java-logger-benchmark/tree/master/benchmark/src/main/java/io/goodforgod/benchmark).
51 |
52 | ### Layout
53 |
54 | All loggers participants are configured to the same layout, so the all participants will be in equal conditions.
55 |
56 | Pseudo layout for all loggers:
57 |
58 | `{date} [{level}] {logger} - {message}{separator}{throwable with stacktrace}`
59 |
60 | Description of layout:
61 | - date - uses formatter `yyyy-MM-dd'T'HH:mm:ss.SSS`
62 | - level - logging level
63 | - logger - logger full class name
64 | - message - logging message
65 | - separator - new line to separate logging messages
66 | - stacktrace - exception stacktrace
67 |
68 | ### Configuration
69 |
70 | All loggers use synchronous output, **without any async appending mechanism**.
71 |
72 | All loggers are configured to output to *STDERR*.
73 |
74 | Benchmark emulates real world usage of loggers, same way logger will be used in real running application.
75 | To achieve this, benchmark uses real IO output for loggers, but to mitigate IO of the specific machine and console output,
76 | all loggers output is redirected to /dev/null.
77 | This is done to benchmark how loggers are working in real environment including IO interactions and avoid benchmarking how machine prints data to STDOUT where benchmark is running at.
78 |
79 | Loggers have different implementations and such huge performance gaps (as seen by results) occur mostly due to some loggers accessing IO more frequently than others.
80 | So measuring IO interactions is indented and critical to receive real world insights.
81 |
82 | ## Setups
83 |
84 | JMH precaution:
85 | ```text
86 | REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
87 | why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
88 | experiments, perform baseline and negative tests that provide experimental control, make sure
89 | the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
90 | Do not assume the numbers tell you what you want them to tell.
91 | ```
92 |
93 | ### Setup 1
94 |
95 | This benchmark results are based on run inside **GitHub CI** and **have forwarded stderr to /dev/null**.
96 |
97 | Benchmark setup configuration:
98 | - OS: Ubuntu ([Github CI](https://github.com/GoodforGod/java-logger-benchmark/actions))
99 | - Processor: Unknown
100 | - Java: JDK 17.0.2, OpenJDK 64-Bit Server VM, 17.0.2+8-LTS
101 | - [Execution](https://github.com/GoodforGod/java-logger-benchmark/blob/master/.github/workflows/gradle.yml#L37-L50): *java -jar benchmark-name.jar 2>/dev/null*
102 |
103 | #### Raw Results
104 |
105 | | Benchmark | Warmup | Runs | Units | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
106 | |---|---|---|---|---|---|---|---|---|
107 | | messageAndStacktrace | 2 | 6 | ops/s | 118216±813 | 115822±428 | 104783±501 | 13338±223 | 40445±203 |
108 | | messageWithoutArguments | 2 | 6 | ops/s | 499217±1199 | 473321±5493 | 417106±6782 | 175836±1835 | 43540±467 |
109 | | messageOneArgumentInTheEnd | 2 | 6 | ops/s | 458897±4559 | 443582±2258 | 400907±5836 | 169457±3192 | 40692±811 |
110 | | messageOneArgumentInTheMiddle | 2 | 6 | ops/s | 473144±13985 | 451131±15834 | 422485±5795 | 173946±1803 | 40464±552 |
111 | | messageOneArgumentInTheStart | 2 | 6 | ops/s | 460671±4028 | 432312±2706 | 406973±6916 | 173542±2095 | 41138±587 |
112 | | messageTwoArgumentInTheEnd | 2 | 6 | ops/s | 452458±6389 | 444213±3966 | 397294±7014 | 164550±3379 | 40661±531 |
113 | | messageTwoArgumentInTheMiddle | 2 | 6 | ops/s | 432949±5454 | 442847±5500 | 390417±3958 | 168683±1862 | 41380±403 |
114 | | messageTwoArgumentInTheStart | 2 | 6 | ops/s | 448363±4246 | 440998±4881 | 392745±10002 | 167334±2699 | 39528±231 |
115 | | messageThreeArgumentInTheEnd | 2 | 6 | ops/s | 423541±3972 | 426526±5837 | 396242±8698 | 169260±1842 | 40128±464 |
116 | | messageThreeArgumentInTheMiddle | 2 | 6 | ops/s | 430087±2801 | 409115±3378 | 392355±5064 | 167569±9936 | 40184±244 |
117 | | messageThreeArgumentInTheStart | 2 | 6 | ops/s | 425695±2946 | 422243±7029 | 373625±6822 | 168490±848 | 39986±586 |
118 |
119 | You can validate [results yourself](https://github.com/GoodforGod/java-logger-benchmark/actions/runs/2004818675).
120 |
121 | #### Processed Results
122 |
123 | If we take [goodforgod-simple-logger](https://github.com/GoodforGod/slf4j-simple-logger) as baseline and compute other loggers performance based on numbers above:
124 |
125 | | Benchmark | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
126 | | ------------------------------- | ----------------- | ------- | ----- | ------------ | ----------- |
127 | | messageAndStacktrace | 100 | 98.0 | 88.6 | 11.3 | 34.2 |
128 | | messageWithoutArguments | 100 | 94.8 | 83.6 | 35.2 | 8.7 |
129 | | messageOneArgumentInTheEnd | 100 | 96.7 | 87.4 | 36.9 | 8.9 |
130 | | messageOneArgumentInTheMiddle | 100 | 95.3 | 89.3 | 36.8 | 8.6 |
131 | | messageOneArgumentInTheStart | 100 | 93.8 | 88.3 | 37.7 | 8.9 |
132 | | messageTwoArgumentInTheEnd | 100 | 98.2 | 87.8 | 36.4 | 9.0 |
133 | | messageTwoArgumentInTheMiddle | 100 | 102.3 | 90.2 | 39.0 | 9.6 |
134 | | messageTwoArgumentInTheStart | 100 | 98.4 | 87.6 | 37.3 | 8.8 |
135 | | messageThreeArgumentInTheEnd | 100 | 100.7 | 93.6 | 40.0 | 9.5 |
136 | | messageThreeArgumentInTheMiddle | 100 | 95.1 | 91.2 | 39.0 | 9.3 |
137 | | messageThreeArgumentInTheStart | 100 | 99.2 | 87.8 | 39.6 | 9.4 |
138 |
139 |
140 | If we shrink results even more and compute average for all messages with arguments as single result then:
141 |
142 | | Benchmark | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
143 | | ---------------------- | ----------------- | ------- | ----- | ------------ | ----------- |
144 | | message and stacktrace | 100 | 98.0 | 88.6 | 11.3 | 34.2 |
145 | | message with arguments | 100 | 97.5 | 88.7 | 37.8 | 9.1 |
146 |
147 | 
148 |
149 | ### Setup 2
150 |
151 | This benchmark **have forwarded stderr to NUL** *(/dev/null analog in windows)*
152 |
153 | Benchmark setup configuration:
154 | - OS: Windows 10
155 | - Processor: AMD Ryzen 2600X
156 | - Java: OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)
157 | - Execution: *java -jar benchmark-name.jar 2>NUL*
158 |
159 | #### Raw Results
160 |
161 | | Benchmark | Warmup | Runs | Units | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
162 | |---|---|---|---|---|---|---|---|---|
163 | | messageAndStacktrace | 2 | 6 | ops/s | 58718±669 | 54617±240 | 43765±605 | 2684±142 | 22721±262 |
164 | | messageWithoutArguments | 2 | 6 | ops/s | 120257±34208 | 101818±5985 | 89485±12457 | 32231±4528 | 31956±747 |
165 | | messageOneArgumentInTheEnd | 2 | 6 | ops/s | 116935±32015 | 93380±13191 | 87549±1835 | 43576±4416 | 29963±355 |
166 | | messageOneArgumentInTheMiddle | 2 | 6 | ops/s | 137995±36420 | 82164±3273 | 90059±17408 | 40252±9626 | 30299±167 |
167 | | messageOneArgumentInTheStart | 2 | 6 | ops/s | 100351±19414 | 88131±5613 | 92676±18736 | 41611±9423 | 30424±353 |
168 | | messageTwoArgumentInTheEnd | 2 | 6 | ops/s | 95318±4567 | 85102±3035 | 87795±7094 | 44082±4324| 29248±548 |
169 | | messageTwoArgumentInTheMiddle | 2 | 6 | ops/s | 101764±13604 | 86166±987 | 96163±28330 | 41920±7623 | 30086±642 |
170 | | messageTwoArgumentInTheStart | 2 | 6 | ops/s | 97099±14191 | 91736±10191 | 85855±4260 | 48236±8364 | 29137±518 |
171 | | messageThreeArgumentInTheEnd | 2 | 6 | ops/s | 99141±11514 | 91344±8744 | 89784±14493 | 46913±3136 | 29543±371 |
172 | | messageThreeArgumentInTheMiddle | 2 | 6 | ops/s | 96524±10997 | 90234±1231 | 89083±11264 | 38981±3724 | 30155±409 |
173 | | messageThreeArgumentInTheStart | 2 | 6 | ops/s | 125277±10888 | 83704±1428 | 86095±2454 | 40526±13953 | 29521±311 |
174 |
175 | #### Processed Results
176 |
177 | If we take [goodforgod-simple-logger](https://github.com/GoodforGod/slf4j-simple-logger) as baseline and compute other loggers performance based on numbers above:
178 |
179 | | Benchmark | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
180 | | ------------------------------- | ----------------- | ------- | ----- | ------------ | ----------- |
181 | | messageAndStacktrace | 100 | 93.0 | 74.5 | 4.6 | 38.7 |
182 | | messageWithoutArguments | 100 | 84.7 | 74.4 | 26.8 | 26.6 |
183 | | messageOneArgumentInTheEnd | 100 | 79.9 | 74.9 | 37.3 | 25.6 |
184 | | messageOneArgumentInTheMiddle | 100 | 59.5 | 65.3 | 29.2 | 22.0 |
185 | | messageOneArgumentInTheStart | 100 | 87.8 | 92.4 | 41.5 | 30.3 |
186 | | messageTwoArgumentInTheEnd | 100 | 89.3 | 92.1 | 46.2 | 30.7 |
187 | | messageTwoArgumentInTheMiddle | 100 | 84.7 | 94.5 | 41.2 | 29.6 |
188 | | messageTwoArgumentInTheStart | 100 | 94.5 | 88.4 | 49.7 | 30.0 |
189 | | messageThreeArgumentInTheEnd | 100 | 92.1 | 90.6 | 47.3 | 29.8 |
190 | | messageThreeArgumentInTheMiddle | 100 | 93.5 | 92.3 | 40.4 | 31.2 |
191 | | messageThreeArgumentInTheStart | 100 | 66.8 | 68.7 | 32.3 | 23.6 |
192 |
193 |
194 | If we shrink results even more and compute average for all messages with arguments as single result then:
195 |
196 | | Benchmark | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
197 | | ---------------------- | ----------------- | ------- | ----- | ------------ | ----------- |
198 | | message and stacktrace | 100 | 93.0 | 74.5 | 4.6 | 38.7 |
199 | | message with arguments | 100 | 83.3 | 83.3 | 39.2 | 27.9 |
200 |
201 | 
202 |
203 | ### Setup 3
204 |
205 | This benchmark **have forwarded stderr to NUL** *(/dev/null analog in windows)*
206 |
207 | Benchmark setup configuration:
208 | - OS: Windows 10
209 | - Processor: Intel i5-6200U
210 | - Java: OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)
211 | - Execution: *java -jar benchmark-name.jar 2>NUL*
212 |
213 | #### Raw Results
214 |
215 | | Benchmark | Warmup | Runs | Units | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
216 | |---|---|---|---|---|---|---|---|---|
217 | | messageAndStacktrace | 2 | 6 | ops/s | 44741±1227 | 30574±551 | 28409±718 | 2074±166 | 15384±161 |
218 | | messageWithoutArguments | 2 | 6 | ops/s | 77648±2357 | 72632±2107 | 70858±4008 | 33142±4502 | 20126±5878 |
219 | | messageOneArgumentInTheEnd | 2 | 6 | ops/s | 75533±4976 | 70459±1576 | 67934±3651 | 32307±12165 | 20420±693 |
220 | | messageOneArgumentInTheMiddle | 2 | 6 | ops/s | 75453±8568 | 71517±3054 | 65894±6387 | 31073±6345 | 20141±585 |
221 | | messageOneArgumentInTheStart | 2 | 6 | ops/s | 73486±15079 | 66942±2062 | 66961±1409 | 31229±7186 | 20163±276 |
222 | | messageTwoArgumentInTheEnd | 2 | 6 | ops/s | 75008±1818 | 66768±4096 | 65697±1048 | 32632±448 | 20421±265 |
223 | | messageTwoArgumentInTheMiddle | 2 | 6 | ops/s | 75396±1473 | 69392±7265 | 68996±4110 | 30265±3249 | 20178±344 |
224 | | messageTwoArgumentInTheStart | 2 | 6 | ops/s | 75785±2851 | 68737±4562 | 67683±1720 | 34428±996 | 20206±239 |
225 | | messageThreeArgumentInTheEnd | 2 | 6 | ops/s | 75579±4230 | 66103±2858 | 66542±2149 | 30621±5432 | 20232±371 |
226 | | messageThreeArgumentInTheMiddle | 2 | 6 | ops/s | 74463±1725 | 69847±1797 | 66406±1474 | 30986±4792 | 20311±333 |
227 | | messageThreeArgumentInTheStart | 2 | 6 | ops/s | 75444±1727 | 68149±3567 | 66786±1621 | 30203±4660 | 20280±315 |
228 |
229 | #### Processed Results
230 |
231 | If we take [goodforgod-simple-logger](https://github.com/GoodforGod/slf4j-simple-logger) as baseline and compute other loggers performance based on numbers above:
232 |
233 | | Benchmark | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
234 | | ------------------------------- | ----------------- | ------- | ----- | ------------ | ----------- |
235 | | messageAndStacktrace | 100 | 68.3 | 63.5 | 4.6 | 34.4 |
236 | | messageWithoutArguments | 100 | 93.5 | 91.3 | 42.7 | 25.9 |
237 | | messageOneArgumentInTheEnd | 100 | 93.3 | 89.9 | 42.8 | 27.0 |
238 | | messageOneArgumentInTheMiddle | 100 | 94.8 | 87.3 | 41.2 | 26.7 |
239 | | messageOneArgumentInTheStart | 100 | 91.1 | 91.1 | 42.5 | 27.4 |
240 | | messageTwoArgumentInTheEnd | 100 | 89.0 | 87.6 | 43.5 | 27.2 |
241 | | messageTwoArgumentInTheMiddle | 100 | 92.0 | 91.5 | 40.1 | 26.8 |
242 | | messageTwoArgumentInTheStart | 100 | 90.7 | 89.3 | 45.4 | 26.7 |
243 | | messageThreeArgumentInTheEnd | 100 | 87.5 | 88.0 | 40.5 | 26.8 |
244 | | messageThreeArgumentInTheMiddle | 100 | 93.8 | 89.2 | 41.6 | 27.3 |
245 | | messageThreeArgumentInTheStart | 100 | 90.3 | 88.5 | 40.0 | 26.9 |
246 |
247 |
248 | If we shrink results even more and compute average for all messages with arguments as single result then:
249 |
250 | | Benchmark | [goodforgod-simple](https://github.com/GoodforGod/slf4j-simple-logger) | [logback](https://logback.qos.ch/) | [log4j](https://logging.apache.org/log4j/2.x/index.html) | [slf4j-simple](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) | [java-system](https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html) |
251 | | ---------------------- | ----------------- | ------- | ----- | ------------ | ----------- |
252 | | message and stacktrace | 100 | 68.3 | 63.5 | 4.6 | 34.4 |
253 | | message with arguments | 100 | 91.6 | 89.4 | 42.0 | 26.9 |
254 |
255 | 
256 |
257 | ## Run
258 |
259 | In case you want to try benchmark yourself, then you should compile and package all benchmarks first:
260 | ```shell
261 | ./gradlew shadowJar
262 | ```
263 |
264 | Then you can run each of them in their proper directory, for example to run *goodforgod-simple-logger* benchmark:
265 | ```shell
266 | java -jar goodforgod-simple-logger/build/libs/*all.jar
267 | ```
268 |
269 | If you want to suppress logger output to measure raw performance, you should redirect STRERR that logger produce to /dev/null.
270 | ```shell
271 | java -jar goodforgod-simple-logger/build/libs/*all.jar 2>/dev/null
272 | ```
273 |
274 | ### Configuration
275 |
276 | You can configure the number of *warmup* and *iterations* with command line arguments, the first argument corresponds to warmups and second is for iterations:
277 |
278 | Example below will run 1 warmup and 2 iteration:
279 | ```shell
280 | java -jar goodforgod-simple-logger/build/libs/*all.jar 1 2
281 | ```
--------------------------------------------------------------------------------
/benchmark/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | implementation "org.slf4j:slf4j-api:1.7.36"
3 | implementation "org.apache.logging.log4j:log4j-api:2.17.2"
4 | }
5 |
6 | shadowJar {
7 | enabled(false)
8 | }
9 |
--------------------------------------------------------------------------------
/benchmark/src/main/java/io/goodforgod/benchmark/Log4jLoggerBenchmark.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.benchmark;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import org.openjdk.jmh.annotations.Benchmark;
6 | import org.openjdk.jmh.annotations.Setup;
7 |
8 | /**
9 | * Log4j benchmark
10 | *
11 | * @author Anton Kurako (GoodforGod)
12 | * @since 09.03.2022
13 | */
14 | public abstract class Log4jLoggerBenchmark extends LoggerBenchmark {
15 |
16 | protected Log4jLoggerBenchmark() {}
17 |
18 | private Logger logger;
19 | private String arg1;
20 | private String arg2;
21 | private String arg3;
22 | private Exception exception;
23 |
24 | @Setup
25 | public void setup() {
26 | try {
27 | throwEx();
28 | } catch (Exception e) {
29 | exception = e;
30 | }
31 |
32 | arg1 = "FirstArgument";
33 | arg2 = "SecondArgument";
34 | arg3 = "ThirdArgument";
35 | logger = LogManager.getLogger(LoggerBenchmark.class);
36 | }
37 |
38 | @Benchmark
39 | public void messageOneArgumentInTheEnd() {
40 | logger.info("Message is printed for this logger and with the argument: {}", arg1);
41 | }
42 |
43 | @Benchmark
44 | public void messageTwoArgumentInTheEnd() {
45 | logger.info("Message is printed for this logger and with arguments {} and {}", arg1, arg2);
46 | }
47 |
48 | @Benchmark
49 | public void messageThreeArgumentInTheEnd() {
50 | logger.info("Message is printed for this logger and with arguments {} and {} and {}", arg1, arg2, arg3);
51 | }
52 |
53 | @Benchmark
54 | public void messageOneArgumentInTheStart() {
55 | logger.info("{} argument and message is printed for this logger", arg1);
56 | }
57 |
58 | @Benchmark
59 | public void messageTwoArgumentInTheStart() {
60 | logger.info("{} and {} arguments and message is printed for this logger", arg1, arg2);
61 | }
62 |
63 | @Benchmark
64 | public void messageThreeArgumentInTheStart() {
65 | logger.info("{} and {} and {} argument and message is printed for this logger", arg1, arg2, arg3);
66 | }
67 |
68 | @Benchmark
69 | public void messageOneArgumentInTheMiddle() {
70 | logger.info("Message is printed for {} argument for this logger", arg1);
71 | }
72 |
73 | @Benchmark
74 | public void messageTwoArgumentInTheMiddle() {
75 | logger.info("Message is printed for {} and {} argument for this logger", arg1, arg2);
76 | }
77 |
78 | @Benchmark
79 | public void messageThreeArgumentInTheMiddle() {
80 | logger.info("Message is printed for {} and {} and {} argument for this logger", arg1, arg2, arg3);
81 | }
82 |
83 | @Benchmark
84 | public void messageWithoutArguments() {
85 | logger.info("Message is printed for this logger without arguments");
86 | }
87 |
88 | @Benchmark
89 | public void messageAndStacktrace() {
90 | logger.info("Message is printed for this logger and there is stacktrace", exception);
91 | }
92 |
93 | // cause we need stacktrace
94 | private void throwEx() throws Exception {
95 | throw new Exception("Some unknown exception happen and have some stacktrace and message info");
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/benchmark/src/main/java/io/goodforgod/benchmark/LoggerBenchmark.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.benchmark;
2 |
3 | import org.openjdk.jmh.annotations.Mode;
4 | import org.openjdk.jmh.runner.Runner;
5 | import org.openjdk.jmh.runner.options.Options;
6 | import org.openjdk.jmh.runner.options.OptionsBuilder;
7 |
8 | /**
9 | * @author Anton Kurako (GoodforGod)
10 | * @since 08.03.2022
11 | */
12 | abstract class LoggerBenchmark {
13 |
14 | LoggerBenchmark() {}
15 |
16 | protected static Runner getBenchmarkRunner(Class> benchType, String[] args) {
17 | return new Runner(getBenchmarkOptions(benchType, args));
18 | }
19 |
20 | protected static Options getBenchmarkOptions(Class> benchType, String[] args) {
21 | final int numberOfIterations = getNumberOfIterations(args);
22 | final int numberOfWarmup = getNumberOfWarmup(args);
23 |
24 | return new OptionsBuilder()
25 | .include(benchType.getSimpleName())
26 | .forks(1)
27 | .mode(Mode.Throughput)
28 | .measurementIterations(numberOfIterations)
29 | .warmupIterations(numberOfWarmup)
30 | .build();
31 | }
32 |
33 | private static int getNumberOfIterations(String[] args) {
34 | return args.length > 0
35 | ? Integer.parseInt(args[0])
36 | : 6;
37 | }
38 |
39 | private static int getNumberOfWarmup(String[] args) {
40 | return args.length > 1
41 | ? Integer.parseInt(args[1])
42 | : 2;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/benchmark/src/main/java/io/goodforgod/benchmark/Slf4jLoggerBenchmark.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.benchmark;
2 |
3 | import org.openjdk.jmh.annotations.Benchmark;
4 | import org.openjdk.jmh.annotations.Setup;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | /**
9 | * sfl4j benchmark
10 | *
11 | * @author Anton Kurako (GoodforGod)
12 | * @since 03.03.2022
13 | */
14 | public abstract class Slf4jLoggerBenchmark extends LoggerBenchmark {
15 |
16 | protected Slf4jLoggerBenchmark() {}
17 |
18 | private Logger logger;
19 | private String arg1;
20 | private String arg2;
21 | private String arg3;
22 | private Exception exception;
23 |
24 | @Setup
25 | public void setup() {
26 | try {
27 | throwEx();
28 | } catch (Exception e) {
29 | exception = e;
30 | }
31 |
32 | arg1 = "FirstArgument";
33 | arg2 = "SecondArgument";
34 | arg3 = "ThirdArgument";
35 | logger = LoggerFactory.getLogger(LoggerBenchmark.class);
36 | }
37 |
38 | @Benchmark
39 | public void messageOneArgumentInTheEnd() {
40 | logger.info("Message is printed for this logger and with the argument: {}", arg1);
41 | }
42 |
43 | @Benchmark
44 | public void messageTwoArgumentInTheEnd() {
45 | logger.info("Message is printed for this logger and with arguments {} and {}", arg1, arg2);
46 | }
47 |
48 | @Benchmark
49 | public void messageThreeArgumentInTheEnd() {
50 | logger.info("Message is printed for this logger and with arguments {} and {} and {}", arg1, arg2, arg3);
51 | }
52 |
53 | @Benchmark
54 | public void messageOneArgumentInTheStart() {
55 | logger.info("{} argument and message is printed for this logger", arg1);
56 | }
57 |
58 | @Benchmark
59 | public void messageTwoArgumentInTheStart() {
60 | logger.info("{} and {} arguments and message is printed for this logger", arg1, arg2);
61 | }
62 |
63 | @Benchmark
64 | public void messageThreeArgumentInTheStart() {
65 | logger.info("{} and {} and {} argument and message is printed for this logger", arg1, arg2, arg3);
66 | }
67 |
68 | @Benchmark
69 | public void messageOneArgumentInTheMiddle() {
70 | logger.info("Message is printed for {} argument for this logger", arg1);
71 | }
72 |
73 | @Benchmark
74 | public void messageTwoArgumentInTheMiddle() {
75 | logger.info("Message is printed for {} and {} argument for this logger", arg1, arg2);
76 | }
77 |
78 | @Benchmark
79 | public void messageThreeArgumentInTheMiddle() {
80 | logger.info("Message is printed for {} and {} and {} argument for this logger", arg1, arg2, arg3);
81 | }
82 |
83 | @Benchmark
84 | public void messageWithoutArguments() {
85 | logger.info("Message is printed for this logger without arguments");
86 | }
87 |
88 | @Benchmark
89 | public void messageAndStacktrace() {
90 | logger.info("Message is printed for this logger and there is stacktrace", exception);
91 | }
92 |
93 | // cause we need stacktrace
94 | private void throwEx() throws Exception {
95 | throw new Exception("Some unknown exception happen and have some stacktrace and message info");
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/benchmark/src/main/java/io/goodforgod/benchmark/SystemLoggerBenchmark.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.benchmark;
2 |
3 | import org.openjdk.jmh.annotations.*;
4 |
5 | /**
6 | * Java System Logger benchmark
7 | *
8 | * @author Anton Kurako (GoodforGod)
9 | * @since 06.03.2022
10 | */
11 | public abstract class SystemLoggerBenchmark extends LoggerBenchmark {
12 |
13 | protected SystemLoggerBenchmark() {}
14 |
15 | private System.Logger logger;
16 | private String arg1;
17 | private String arg2;
18 | private String arg3;
19 | private Exception exception;
20 |
21 | @Setup
22 | public void setup() {
23 | try {
24 | throwEx();
25 | } catch (Exception e) {
26 | exception = e;
27 | }
28 |
29 | arg1 = "FirstArgument";
30 | arg2 = "SecondArgument";
31 | arg3 = "ThirdArgument";
32 | logger = System.getLogger(LoggerBenchmark.class.getName());
33 | }
34 |
35 | @Benchmark
36 | public void messageOneArgumentInTheEnd() {
37 | logger.log(System.Logger.Level.INFO, "Message is printed for this logger and with the argument: {0}", arg1);
38 | }
39 |
40 | @Benchmark
41 | public void messageTwoArgumentInTheEnd() {
42 | logger.log(System.Logger.Level.INFO, "Message is printed for this logger and with arguments {0} and {1}", arg1, arg2);
43 | }
44 |
45 | @Benchmark
46 | public void messageThreeArgumentInTheEnd() {
47 | logger.log(System.Logger.Level.INFO, "Message is printed for this logger and with arguments {0} and {1} and {2}",
48 | arg1, arg2, arg3);
49 | }
50 |
51 | @Benchmark
52 | public void messageOneArgumentInTheStart() {
53 | logger.log(System.Logger.Level.INFO, "{0} argument and message is printed for this logger", arg1);
54 | }
55 |
56 | @Benchmark
57 | public void messageTwoArgumentInTheStart() {
58 | logger.log(System.Logger.Level.INFO, "{0} and {1} arguments and message is printed for this logger", arg1, arg2);
59 | }
60 |
61 | @Benchmark
62 | public void messageThreeArgumentInTheStart() {
63 | logger.log(System.Logger.Level.INFO, "{0} and {1} and {2} argument and message is printed for this logger", arg1,
64 | arg2, arg3);
65 | }
66 |
67 | @Benchmark
68 | public void messageOneArgumentInTheMiddle() {
69 | logger.log(System.Logger.Level.INFO, "Message is printed for {0} argument for this logger", arg1);
70 | }
71 |
72 | @Benchmark
73 | public void messageTwoArgumentInTheMiddle() {
74 | logger.log(System.Logger.Level.INFO, "Message is printed for {0} and {1} argument for this logger", arg1, arg2);
75 | }
76 |
77 | @Benchmark
78 | public void messageThreeArgumentInTheMiddle() {
79 | logger.log(System.Logger.Level.INFO, "Message is printed for {0} and {1} and {2} argument for this logger", arg1,
80 | arg2, arg3);
81 | }
82 |
83 | @Benchmark
84 | public void messageWithoutArguments() {
85 | logger.log(System.Logger.Level.INFO, "Message is printed for this logger without arguments");
86 | }
87 |
88 | @Benchmark
89 | public void messageAndStacktrace() {
90 | logger.log(System.Logger.Level.INFO, "Message is printed for this logger and there is stacktrace", exception);
91 | }
92 |
93 | // cause we need stacktrace
94 | private void throwEx() throws Exception {
95 | throw new Exception("Some unknown exception happen and have some stacktrace and message info");
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "java"
3 | id "application"
4 |
5 | id "com.diffplug.spotless" version "6.1.0"
6 | id "com.github.johnrengelman.shadow" version "7.1.0"
7 | }
8 |
9 | group = groupId
10 | version = artifactVersion
11 |
12 | sourceCompatibility = JavaVersion.VERSION_17
13 | targetCompatibility = JavaVersion.VERSION_17
14 |
15 | shadowJar {
16 | enabled(false)
17 | }
18 |
19 | subprojects {
20 | apply plugin: "java"
21 | apply plugin: "application"
22 | apply plugin: "com.diffplug.spotless"
23 | apply plugin: "com.github.johnrengelman.shadow"
24 |
25 | repositories {
26 | mavenLocal()
27 | mavenCentral()
28 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
29 | maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots" }
30 | }
31 |
32 | group = groupId
33 | version = artifactVersion
34 |
35 | sourceCompatibility = JavaVersion.VERSION_17
36 | targetCompatibility = JavaVersion.VERSION_17
37 |
38 | dependencies {
39 | annotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:1.34"
40 | implementation "org.openjdk.jmh:jmh-core:1.34"
41 | }
42 |
43 | spotless {
44 | java {
45 | encoding("UTF-8")
46 | importOrder()
47 | removeUnusedImports()
48 | eclipse("4.21.0").configFile("${rootDir}/config/codestyle.xml")
49 | }
50 | }
51 |
52 | jar.enabled(true)
53 |
54 | artifacts {
55 | archives shadowJar
56 | }
57 |
58 | tasks.withType(JavaCompile) {
59 | options.encoding("UTF-8")
60 | options.incremental(true)
61 | options.fork = true
62 | }
63 | }
--------------------------------------------------------------------------------
/config/codestyle.xml:
--------------------------------------------------------------------------------
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 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
--------------------------------------------------------------------------------
/docs/setup-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodforGod/java-logger-benchmark/ca15e0a6840ed752f6eff8a709531a32ea1b9d3e/docs/setup-1.png
--------------------------------------------------------------------------------
/docs/setup-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodforGod/java-logger-benchmark/ca15e0a6840ed752f6eff8a709531a32ea1b9d3e/docs/setup-2.png
--------------------------------------------------------------------------------
/docs/setup-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodforGod/java-logger-benchmark/ca15e0a6840ed752f6eff8a709531a32ea1b9d3e/docs/setup-3.png
--------------------------------------------------------------------------------
/goodforgod-simple-logger/build.gradle:
--------------------------------------------------------------------------------
1 | mainClassName = "io.goodforgod.slf4j.Bench"
2 |
3 | dependencies {
4 | implementation project(":benchmark")
5 |
6 | implementation "io.goodforgod:slf4j-simple-logger:0.13.0"
7 | }
8 |
9 | shadowJar {
10 | mergeServiceFiles()
11 | manifest {
12 | attributes "Main-Class": mainClassName
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/goodforgod-simple-logger/src/main/java/io/goodforgod/slf4j/Bench.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.slf4j;
2 |
3 | import io.goodforgod.benchmark.Slf4jLoggerBenchmark;
4 | import org.openjdk.jmh.annotations.*;
5 | import org.openjdk.jmh.runner.RunnerException;
6 |
7 | @State(Scope.Benchmark)
8 | public class Bench extends Slf4jLoggerBenchmark {
9 |
10 | public static void main(String[] args) throws RunnerException {
11 | getBenchmarkRunner(Bench.class, args).run();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/goodforgod-simple-logger/src/main/resources/simplelogger.properties:
--------------------------------------------------------------------------------
1 | org.slf4j.simpleLogger.defaultLogLevel=DEBUG
2 | org.slf4j.simpleLogger.showDateTime=true
3 | org.slf4j.simpleLogger.dateTimeFormat=uuuu-MM-dd'T'HH:mm:ss.SSS
4 | org.slf4j.simpleLogger.showThreadName=false
5 | org.slf4j.simpleLogger.showLogName=true
6 | org.slf4j.simpleLogger.levelInBrackets=true
7 | org.slf4j.simpleLogger.charset=null
8 | org.slf4j.simpleLogger.logFile=System.err
9 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | groupId=io.goodforgod
2 | artifactId=java-logger-benchmark
3 | artifactVersion=0.18.0
4 |
5 |
6 | ##### GRADLE #####
7 | org.gradle.daemon=true
8 | org.gradle.parallel=true
9 | org.gradle.configureondemand=true
10 | org.gradle.caching=true
11 | org.gradle.jvmargs=-Dfile.encoding=UTF-8 \
12 | --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
13 | --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
14 | --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
15 | --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
16 | --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
17 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoodforGod/java-logger-benchmark/ca15e0a6840ed752f6eff8a709531a32ea1b9d3e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84 |
85 | APP_NAME="Gradle"
86 | APP_BASE_NAME=${0##*/}
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | MAX_FD=$( ulimit -H -n ) ||
147 | warn "Could not query maximum file descriptor limit"
148 | esac
149 | case $MAX_FD in #(
150 | '' | soft) :;; #(
151 | *)
152 | ulimit -n "$MAX_FD" ||
153 | warn "Could not set maximum file descriptor limit to $MAX_FD"
154 | esac
155 | fi
156 |
157 | # Collect all arguments for the java command, stacking in reverse order:
158 | # * args from the command line
159 | # * the main class name
160 | # * -classpath
161 | # * -D...appname settings
162 | # * --module-path (only if needed)
163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164 |
165 | # For Cygwin or MSYS, switch paths to Windows format before running java
166 | if "$cygwin" || "$msys" ; then
167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169 |
170 | JAVACMD=$( cygpath --unix "$JAVACMD" )
171 |
172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
173 | for arg do
174 | if
175 | case $arg in #(
176 | -*) false ;; # don't mess with options #(
177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
178 | [ -e "$t" ] ;; #(
179 | *) false ;;
180 | esac
181 | then
182 | arg=$( cygpath --path --ignore --mixed "$arg" )
183 | fi
184 | # Roll the args list around exactly as many times as the number of
185 | # args, so each arg winds up back in the position where it started, but
186 | # possibly modified.
187 | #
188 | # NB: a `for` loop captures its iteration list before it begins, so
189 | # changing the positional parameters here affects neither the number of
190 | # iterations, nor the values presented in `arg`.
191 | shift # remove old arg
192 | set -- "$@" "$arg" # push replacement arg
193 | done
194 | fi
195 |
196 | # Collect all arguments for the java command;
197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198 | # shell script including quotes and variable substitutions, so put them in
199 | # double quotes to make sure that they get re-expanded; and
200 | # * put everything else in single quotes, so that it's not re-expanded.
201 |
202 | set -- \
203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
204 | -classpath "$CLASSPATH" \
205 | org.gradle.wrapper.GradleWrapperMain \
206 | "$@"
207 |
208 | # Use "xargs" to parse quoted args.
209 | #
210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211 | #
212 | # In Bash we could simply go:
213 | #
214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215 | # set -- "${ARGS[@]}" "$@"
216 | #
217 | # but POSIX shell has neither arrays nor command substitution, so instead we
218 | # post-process each arg (as a line of input to sed) to backslash-escape any
219 | # character that might be a shell metacharacter, then use eval to reverse
220 | # that process (while maintaining the separation between arguments), and wrap
221 | # the whole thing up as a single "set" statement.
222 | #
223 | # This will of course break if any of these variables contains a newline or
224 | # an unmatched quote.
225 | #
226 |
227 | eval "set -- $(
228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229 | xargs -n1 |
230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231 | tr '\n' ' '
232 | )" '"$@"'
233 |
234 | exec "$JAVACMD" "$@"
235 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/log4j-logger/build.gradle:
--------------------------------------------------------------------------------
1 | mainClassName = "io.goodforgod.log4j.Bench"
2 |
3 | dependencies {
4 | implementation project(":benchmark")
5 |
6 | implementation "org.apache.logging.log4j:log4j-core:2.17.2"
7 | }
8 |
9 | shadowJar {
10 | mergeServiceFiles()
11 | manifest {
12 | attributes "Main-Class": mainClassName
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/log4j-logger/src/main/java/io/goodforgod/log4j/Bench.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.log4j;
2 |
3 | import io.goodforgod.benchmark.Log4jLoggerBenchmark;
4 | import org.openjdk.jmh.annotations.Scope;
5 | import org.openjdk.jmh.annotations.State;
6 | import org.openjdk.jmh.runner.RunnerException;
7 |
8 | @State(Scope.Benchmark)
9 | public class Bench extends Log4jLoggerBenchmark {
10 |
11 | public static void main(String[] args) throws RunnerException {
12 | getBenchmarkRunner(Bench.class, args).run();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/log4j-logger/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/logback-logger/build.gradle:
--------------------------------------------------------------------------------
1 | mainClassName = "io.goodforgod.slf4j.Bench"
2 |
3 | dependencies {
4 | implementation project(":benchmark")
5 |
6 | implementation "ch.qos.logback:logback-classic:1.2.11"
7 | }
8 |
9 | shadowJar {
10 | mergeServiceFiles()
11 | manifest {
12 | attributes "Main-Class": mainClassName
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/logback-logger/src/main/java/io/goodforgod/slf4j/Bench.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.slf4j;
2 |
3 | import io.goodforgod.benchmark.Slf4jLoggerBenchmark;
4 | import org.openjdk.jmh.annotations.*;
5 | import org.openjdk.jmh.runner.RunnerException;
6 |
7 | @State(Scope.Benchmark)
8 | public class Bench extends Slf4jLoggerBenchmark {
9 |
10 | public static void main(String[] args) throws RunnerException {
11 | getBenchmarkRunner(Bench.class, args).run();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/logback-logger/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | System.err
5 |
6 | %d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%level] %logger - %msg%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = artifactId
2 |
3 | include 'slf4j-simple-logger'
4 | include 'goodforgod-simple-logger'
5 | include 'logback-logger'
6 | include 'benchmark'
7 | include 'system-logger'
8 | include 'log4j-logger'
9 |
10 |
--------------------------------------------------------------------------------
/slf4j-simple-logger/build.gradle:
--------------------------------------------------------------------------------
1 | mainClassName = "io.goodforgod.slf4j.Bench"
2 |
3 | dependencies {
4 | implementation project(":benchmark")
5 |
6 | implementation "org.slf4j:slf4j-simple:1.7.36"
7 | }
8 |
9 | shadowJar {
10 | mergeServiceFiles()
11 | manifest {
12 | attributes "Main-Class": mainClassName
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/slf4j-simple-logger/src/main/java/io/goodforgod/slf4j/Bench.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.slf4j;
2 |
3 | import io.goodforgod.benchmark.Slf4jLoggerBenchmark;
4 | import org.openjdk.jmh.annotations.*;
5 | import org.openjdk.jmh.runner.RunnerException;
6 |
7 | @State(Scope.Benchmark)
8 | public class Bench extends Slf4jLoggerBenchmark {
9 |
10 | public static void main(String[] args) throws RunnerException {
11 | getBenchmarkRunner(Bench.class, args).run();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/slf4j-simple-logger/src/main/resources/simplelogger.properties:
--------------------------------------------------------------------------------
1 | org.slf4j.simpleLogger.defaultLogLevel=DEBUG
2 | org.slf4j.simpleLogger.showDateTime=true
3 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd'T'HH:mm:ss.SSS
4 | org.slf4j.simpleLogger.showThreadName=false
5 | org.slf4j.simpleLogger.showLogName=true
6 | org.slf4j.simpleLogger.levelInBrackets=true
7 | org.slf4j.simpleLogger.logFile=System.err
8 |
--------------------------------------------------------------------------------
/system-logger/build.gradle:
--------------------------------------------------------------------------------
1 | mainClassName = "io.goodforgod.system.Bench"
2 |
3 | dependencies {
4 | implementation project(":benchmark")
5 | }
6 |
7 | shadowJar {
8 | mergeServiceFiles()
9 | manifest {
10 | attributes "Main-Class": mainClassName
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/system-logger/src/main/java/io/goodforgod/system/Bench.java:
--------------------------------------------------------------------------------
1 | package io.goodforgod.system;
2 |
3 | import io.goodforgod.benchmark.SystemLoggerBenchmark;
4 | import org.openjdk.jmh.annotations.*;
5 | import org.openjdk.jmh.runner.RunnerException;
6 |
7 | @State(Scope.Benchmark)
8 | public class Bench extends SystemLoggerBenchmark {
9 |
10 | public static void main(String[] args) throws RunnerException {
11 | getBenchmarkRunner(Bench.class, args).run();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------