Matthias Andreas Benkard | 47df8be | 2024-06-23 16:24:11 +0200 | [diff] [blame] | 1 | package eu.mulk.quarkus.googlecloud.jsonlogging; |
| 2 | |
| 3 | import java.util.List; |
| 4 | import org.jboss.logmanager.ExtLogRecord; |
| 5 | import org.openjdk.jmh.annotations.*; |
| 6 | import org.openjdk.jmh.infra.Blackhole; |
| 7 | |
| 8 | @Warmup(iterations = 5, time = 1) |
| 9 | @Measurement(iterations = 10, time = 1) |
| 10 | @Fork(value = 1) |
| 11 | @State(org.openjdk.jmh.annotations.Scope.Benchmark) |
| 12 | public class FormatterBenchmark { |
| 13 | |
| 14 | private ExtLogRecord simpleLogRecord; |
| 15 | private ExtLogRecord structuredLogRecord; |
Matthias Andreas Benkard | f90824b | 2024-06-23 16:42:11 +0200 | [diff] [blame] | 16 | private ExtLogRecord massivelyStructuredLogRecord; |
Matthias Andreas Benkard | 47df8be | 2024-06-23 16:24:11 +0200 | [diff] [blame] | 17 | private Formatter formatter; |
| 18 | |
| 19 | @Setup |
| 20 | public void setup() { |
| 21 | simpleLogRecord = FormatterTest.makeSimpleRecord(); |
| 22 | structuredLogRecord = FormatterTest.makeStructuredRecord(); |
Matthias Andreas Benkard | f90824b | 2024-06-23 16:42:11 +0200 | [diff] [blame] | 23 | massivelyStructuredLogRecord = FormatterTest.makeMassivelyStructuredRecord(); |
Matthias Andreas Benkard | 47df8be | 2024-06-23 16:24:11 +0200 | [diff] [blame] | 24 | formatter = new Formatter(List.of(), List.of()); |
| 25 | } |
| 26 | |
| 27 | @Benchmark |
| 28 | public void simpleLogRecord(Blackhole blackhole) { |
| 29 | blackhole.consume(formatter.format(simpleLogRecord)); |
| 30 | } |
| 31 | |
| 32 | @Benchmark |
| 33 | public void structuredLogRecord(Blackhole blackhole) { |
| 34 | blackhole.consume(formatter.format(structuredLogRecord)); |
| 35 | } |
Matthias Andreas Benkard | f90824b | 2024-06-23 16:42:11 +0200 | [diff] [blame] | 36 | |
| 37 | @Benchmark |
| 38 | public void massivelyStructuredLogRecord(Blackhole blackhole) { |
| 39 | var f = formatter.format(massivelyStructuredLogRecord); |
| 40 | blackhole.consume(f); |
| 41 | } |
Matthias Andreas Benkard | 47df8be | 2024-06-23 16:24:11 +0200 | [diff] [blame] | 42 | } |