You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/03/16 17:37:20 UTC

[GitHub] [kafka] ijuma commented on a change in pull request #10324: MINOR: Add a few more benchmark for the timeline map

ijuma commented on a change in pull request #10324:
URL: https://github.com/apache/kafka/pull/10324#discussion_r595396880



##########
File path: jmh-benchmarks/src/main/java/org/apache/kafka/jmh/timeline/TimelineHashMapBenchmark.java
##########
@@ -44,33 +49,126 @@
 public class TimelineHashMapBenchmark {
     private final static int NUM_ENTRIES = 1_000_000;
 
+    @State(Scope.Thread)
+    public static class HashMapInput {
+        public HashMap<Integer, String> map;
+        public final List<Integer> keys = createKeys(NUM_ENTRIES);
+
+        @Setup(Level.Invocation)
+        public void setup() {
+            map = new HashMap<>(keys.size());
+            for (Integer key : keys) {
+                map.put(key, String.valueOf(key));
+            }
+
+            Collections.shuffle(keys);
+        }
+    }
+
+    @State(Scope.Thread)
+    public static class ImmutableMapInput {
+        scala.collection.immutable.HashMap<Integer, String> map;
+        public final List<Integer> keys = createKeys(NUM_ENTRIES);
+
+        @Setup(Level.Invocation)
+        public void setup() {
+            map = new scala.collection.immutable.HashMap<>();
+            for (Integer key : keys) {
+                map = map.updated(key, String.valueOf(key));
+            }
+
+            Collections.shuffle(keys);
+        }
+    }
+
+    @State(Scope.Thread)
+    public static class TimelineMapInput {
+        public SnapshotRegistry snapshotRegistry;
+        public TimelineHashMap<Integer, String> map;
+        public final List<Integer> keys = createKeys(NUM_ENTRIES);
+
+        @Setup(Level.Invocation)
+        public void setup() {
+            snapshotRegistry = new SnapshotRegistry(new LogContext());
+            map = new TimelineHashMap<>(snapshotRegistry, keys.size());
+
+            for (Integer key : keys) {
+                map.put(key, String.valueOf(key));
+            }
+
+            Collections.shuffle(keys);
+        }
+    }
+
+    @State(Scope.Thread)
+    public static class TimelineMapSnapshotInput {
+        public SnapshotRegistry snapshotRegistry;
+        public TimelineHashMap<Integer, String> map;
+        public final List<Integer> keys = createKeys(NUM_ENTRIES);
+
+        @Setup(Level.Invocation)
+        public void setup() {
+            snapshotRegistry = new SnapshotRegistry(new LogContext());
+            map = new TimelineHashMap<>(snapshotRegistry, keys.size());
+
+            for (Integer key : keys) {
+                map.put(key, String.valueOf(key));
+            }
+
+            int count = 0;
+            for (Integer key : keys) {
+                if (count % 1_000 == 0) {
+                    snapshotRegistry.deleteSnapshotsUpTo(count - 10_000);
+                    snapshotRegistry.createSnapshot(count);
+                }
+                map.put(key, String.valueOf(key));
+                count++;
+            }
+
+            Collections.shuffle(keys);
+        }
+    }
+
+
     @Benchmark
     public Map<Integer, String> testAddEntriesInHashMap() {
-        HashMap<Integer, String> map = new HashMap<>(NUM_ENTRIES);
+        HashMap<Integer, String> map = new HashMap<>();
         for (int i = 0; i < NUM_ENTRIES; i++) {
             int key = (int) (0xffffffff & ((i * 2862933555777941757L) + 3037000493L));
             map.put(key, String.valueOf(key));
         }
+
+        return map;
+    }
+
+    @Benchmark
+    public scala.collection.immutable.HashMap<Integer, String> testAddEntriesInImmutableMap() {
+        scala.collection.immutable.HashMap<Integer, String> map = new scala.collection.immutable.HashMap<>();
+        for (int i = 0; i < NUM_ENTRIES; i++) {
+            int key = (int) (0xffffffff & ((i * 2862933555777941757L) + 3037000493L));
+            map = map.updated(key, String.valueOf(key));

Review comment:
       We don't want to be converting from int to string in the benchmark code.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org