Skip to content

Commit 8573ef7

Browse files
committedMay 24, 2024··
Try to add more workload to TC vs SC test
1 parent 7bbff89 commit 8573ef7

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,16 @@ public void setup() {
105105

106106
@Benchmark
107107
public void threadContextMap(final Blackhole blackhole) {
108-
for (int i = 0; i < count; i++) {
109-
ThreadContext.put(keys[i], values[i]);
108+
try {
109+
for (int i = 0; i < count; i++) {
110+
ThreadContext.put(keys[i], values[i]);
111+
}
112+
for (int i = 0; i < count; i++) {
113+
blackhole.consume(ThreadContext.get(keys[i]));
114+
}
115+
} finally {
116+
ThreadContext.clearMap();
110117
}
111-
blackhole.consume(values);
112-
ThreadContext.clearMap();
113118
}
114119

115120
@Benchmark
@@ -118,6 +123,10 @@ public void scopedContext(final Blackhole blackhole) {
118123
for (int i = 1; i < count; i++) {
119124
instance.where(keys[i], values[i]);
120125
}
121-
instance.run(() -> blackhole.consume(values));
126+
instance.run(() -> {
127+
for (int i = 0; i < count; i++) {
128+
ScopedContext.get(keys[i]);
129+
}
130+
});
122131
}
123132
}

0 commit comments

Comments
 (0)
Please sign in to comment.