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



##########
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));
+        }
+
         return map;
     }
 
     @Benchmark
     public Map<Integer, String> testAddEntriesInTimelineMap() {
         SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new 
LogContext());
-        TimelineHashMap<Integer, String> map =
-            new TimelineHashMap<>(snapshotRegistry, NUM_ENTRIES);
+        TimelineHashMap<Integer, String> map = new 
TimelineHashMap<>(snapshotRegistry, 16);
         for (int i = 0; i < NUM_ENTRIES; i++) {
             int key = (int) (0xffffffff & ((i * 2862933555777941757L) + 
3037000493L));

Review comment:
       I think this is an algorithm for generating pseudo random number. I 
think it relates to https://nuclear.llnl.gov/CNP/rng/rngman/node4.html.
   
   If this is true, let me fix the expression as it is supposed to multiply by 
`key` not `i`.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to