This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 8573ef778d Try to add more workload to TC vs SC test
8573ef778d is described below

commit 8573ef778d2fad2bbec50a687955dccd2a616cc5
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Sat May 25 00:18:06 2024 +0200

    Try to add more workload to TC vs SC test
---
 .../jmh/ThreadContextVsScopedContextBenchmark.java    | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git 
a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextVsScopedContextBenchmark.java
 
b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextVsScopedContextBenchmark.java
index df10cfaa20..068bb53815 100644
--- 
a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextVsScopedContextBenchmark.java
+++ 
b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadContextVsScopedContextBenchmark.java
@@ -105,11 +105,16 @@ public class ThreadContextVsScopedContextBenchmark {
 
     @Benchmark
     public void threadContextMap(final Blackhole blackhole) {
-        for (int i = 0; i < count; i++) {
-            ThreadContext.put(keys[i], values[i]);
+        try {
+            for (int i = 0; i < count; i++) {
+                ThreadContext.put(keys[i], values[i]);
+            }
+            for (int i = 0; i < count; i++) {
+                blackhole.consume(ThreadContext.get(keys[i]));
+            }
+        } finally {
+            ThreadContext.clearMap();
         }
-        blackhole.consume(values);
-        ThreadContext.clearMap();
     }
 
     @Benchmark
@@ -118,6 +123,10 @@ public class ThreadContextVsScopedContextBenchmark {
         for (int i = 1; i < count; i++) {
             instance.where(keys[i], values[i]);
         }
-        instance.run(() -> blackhole.consume(values));
+        instance.run(() -> {
+            for (int i = 0; i < count; i++) {
+                ScopedContext.get(keys[i]);
+            }
+        });
     }
 }

Reply via email to