Skip to content

Commit 8a01c7b

Browse files
committed
Add benchmark
1 parent 7f126de commit 8a01c7b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/UuidGeneratorBenchmark.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
package org.apache.logging.log4j.perf.jmh;
1818

1919
import java.util.UUID;
20+
import org.apache.logging.log4j.core.LogEvent;
21+
import org.apache.logging.log4j.core.test.layout.LogEventFixtures;
2022
import org.apache.logging.log4j.core.util.UuidUtil;
2123
import org.openjdk.jmh.annotations.Benchmark;
24+
import org.openjdk.jmh.annotations.Scope;
25+
import org.openjdk.jmh.annotations.State;
2226

2327
/**
24-
* Compares random UUID generation with time-based UUID generation.
28+
* Compares UUID generators.
2529
*/
2630
// ============================== HOW TO RUN THIS TEST: ====================================
2731
//
@@ -31,6 +35,10 @@
3135
// java -jar log4j-perf/target/benchmarks.jar -help
3236
//
3337
public class UuidGeneratorBenchmark {
38+
@State(Scope.Benchmark)
39+
public static class UuidGeneratorBenchmarkState {
40+
private final LogEvent logEvent = LogEventFixtures.createLogEvent();
41+
}
3442

3543
@Benchmark
3644
public UUID base() {
@@ -46,4 +54,9 @@ public UUID randomUUID() {
4654
public UUID timeBasedUUID() {
4755
return UuidUtil.getTimeBasedUuid();
4856
}
57+
58+
@Benchmark
59+
public UUID hashBasedUuid(UuidGeneratorBenchmarkState state) {
60+
return UuidUtil.getHashBasedUuid(state.logEvent);
61+
}
4962
}

0 commit comments

Comments
 (0)