You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/08/23 13:37:20 UTC

[2/5] logging-log4j2 git commit: LOG4J2-1349 fixed ArrayContextDataVsHashMapBenchmark for get and put

LOG4J2-1349 fixed ArrayContextDataVsHashMapBenchmark for get and put


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/44784df9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/44784df9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/44784df9

Branch: refs/heads/LOG4J2-1349-gcfree-threadcontext
Commit: 44784df948213a72ba140d89d1249b3af6c2ed3c
Parents: 049e679
Author: rpopma <rp...@apache.org>
Authored: Tue Aug 23 21:01:51 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Tue Aug 23 21:01:51 2016 +0900

----------------------------------------------------------------------
 .../jmh/ArrayContextDataVsHashMapBenchmark.java | 53 ++++----------------
 1 file changed, 10 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44784df9/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ArrayContextDataVsHashMapBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ArrayContextDataVsHashMapBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ArrayContextDataVsHashMapBenchmark.java
index ada45b4..eb354a5 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ArrayContextDataVsHashMapBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ArrayContextDataVsHashMapBenchmark.java
@@ -205,68 +205,35 @@ public class ArrayContextDataVsHashMapBenchmark {
     }
 
     @Benchmark
-    public int getValueArrayContextData() {
-        String[] theKeys = keys;
-        int c = count;
-        int result = 0;
-        for (int i = 0; i < c; i++) {
-            Object val = populatedContextData.getValue(theKeys[i]);
-            result += val.hashCode();// + theKeys[i].hashCode();
-        }
-        return result;
+    public Object getValueArrayContextData() {
+        return populatedContextData.getValue(keys[count - 1]);
     }
 
     @Benchmark
-    public int getValueHashContextData() {
-        String[] theKeys = keys;
-        int c = count;
-        int result = 0;
-        for (int i = 0; i < c; i++) {
-            Object val = populatedHashContextData.getValue(theKeys[i]);
-            result += val.hashCode();// + theKeys[i].hashCode();
-        }
-        return result;
+    public Object getValueHashContextData() {
+        return populatedHashContextData.getValue(keys[count - 1]);
     }
 
     @Benchmark
-    public int getValueMap() {
-        String[] theKeys = keys;
-        int c = count;
-        int result = 0;
-        for (int i = 0; i < c; i++) {
-            Object val = populatedMap.get(theKeys[i]);
-            result += val.hashCode();// + theKeys[i].hashCode();
-        }
-        return result;
+    public Object getValueMap() {
+        return populatedMap.get(keys[count - 1]);
     }
 
     @Benchmark
     public int putArrayContextData() {
-        String[] theKeys = keys;
-        int c = count;
-        for (int i = 0; i < c; i++) {
-            contextData.putValue(theKeys[i], value);
-        }
-        return contextData.size();
+        populatedContextData.put("someKey", "someValue");
+        return populatedContextData.size();
     }
 
     @Benchmark
     public int putHashContextData() {
-        String[] theKeys = keys;
-        int c = count;
-        for (int i = 0; i < c; i++) {
-            hashContextData.putValue(theKeys[i], value);
-        }
+        hashContextData.put("someKey", "someValue");
         return hashContextData.size();
     }
 
     @Benchmark
     public int putMap() {
-        String[] theKeys = keys;
-        int c = count;
-        for (int i = 0; i < c; i++) {
-            map.put(theKeys[i], value);
-        }
+        map.put("someKey", "someValue");
         return map.size();
     }
 }
\ No newline at end of file