Skip to content

Commit 604e138

Browse files
📝 Add docstrings to pure
Docstrings generation was requested by @magicprinc. * #1 (comment) The following files were modified: * `src/jmh/java/com/trivago/kangaroo/AbstractBenchHelper.java` * `src/jmh/java/com/trivago/kangaroo/AbstractCommonBenchHelper.java` * `src/jmh/java/com/trivago/kangaroo/FastutilWrapperBusyWaitingBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/FastutilWrapperDefaultBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/JavaUtilWrapperBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/long2long/AbstractLongLongBenchHelper.java` * `src/jmh/java/com/trivago/kangaroo/long2long/FastutilWrapperBusyWaitingLongLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/long2long/FastutilWrapperDefaultLongLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/long2long/JavaConcurrentLongLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/long2long/JavaUtilWrapperLongLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/object2long/AbstractObjectLongBenchHelper.java` * `src/jmh/java/com/trivago/kangaroo/object2long/FastutilWrapperBusyWaitingObjectLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/object2long/FastutilWrapperDefaultObjectLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/object2long/JavaConcurrentObjectLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/object2long/JavaUtilWrapperObjectLongBenchmark.java` * `src/jmh/java/com/trivago/kangaroo/object2long/TestObjectKey.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/PrimitiveConcurrentMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/intkey/ConcurrentBusyWaitingIntFloatMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/intkey/ConcurrentBusyWaitingIntIntMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/intkey/ConcurrentIntFloatMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/intkey/ConcurrentIntIntMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentBusyWaitingLongFloatMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentBusyWaitingLongIntMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentBusyWaitingLongLongMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentBusyWaitingLongObjectMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentLongFloatMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentLongIntMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentLongLongMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/longkey/ConcurrentLongObjectMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/objkey/ConcurrentBusyWaitingObjectLongMap.java` * `src/main/java/com/trivago/fastutilconcurrentwrapper/objkey/ConcurrentObjectLongMap.java`
1 parent 03158b8 commit 604e138

31 files changed

+1521
-18
lines changed

src/jmh/java/com/trivago/kangaroo/AbstractBenchHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ public abstract class AbstractBenchHelper extends AbstractCommonBenchHelper {
99
protected static final int NUM_VALUES = 1_000_000;
1010
protected ConcurrentLongLongMap map;
1111

12+
/**
13+
* Initializes the concurrent map with a pre-populated set of random key-value pairs.
14+
*
15+
* <p>The map is configured with 16 buckets, an initial capacity defined by {@code NUM_VALUES},
16+
* and a load factor of 0.8. When the {@code mode} parameter is {@code BUSY_WAITING}, the map is built
17+
* with busy-waiting behavior; otherwise, a default configuration is used. After initialization,
18+
* the map is populated with {@code NUM_VALUES} entries, each assigned random long keys and values
19+
* generated via {@link ThreadLocalRandom}.</p>
20+
*
21+
* @param mode the map mode that determines whether busy-waiting is enabled
22+
*/
1223
public void initAndLoadData(PrimitiveMapBuilder.MapMode mode) {
1324
if (mode == PrimitiveMapBuilder.MapMode.BUSY_WAITING){
1425
map = ConcurrentLongLongMap.newBuilder()

src/jmh/java/com/trivago/kangaroo/AbstractCommonBenchHelper.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
import java.util.concurrent.TimeUnit;
1010

1111
public abstract class AbstractCommonBenchHelper {
12+
/**
13+
* Benchmarks the throughput of the "get" operation.
14+
*
15+
* <p>This method executes the testGet() operation using the throughput mode and measures its performance
16+
* with 4 concurrent threads.
17+
*/
1218
@Threads(4)
1319
@Benchmark
1420
@BenchmarkMode(Mode.Throughput)
@@ -46,6 +52,13 @@ public void testRandomPutAvgTime() {
4652
testPut();
4753
}
4854

55+
/**
56+
* Measures the average execution time of all operations.
57+
* <p>
58+
* Executes the {@code testAllOps()} method across four concurrent threads
59+
* and reports the average execution time in nanoseconds.
60+
* </p>
61+
*/
4962
@Threads(4)
5063
@Benchmark
5164
@BenchmarkMode(Mode.AverageTime)
@@ -54,9 +67,28 @@ public void testRandomAllOpsAvgTime() {
5467
testAllOps();
5568
}
5669

57-
public abstract void testGet();
70+
/**
71+
* Executes the GET operation benchmark.
72+
*
73+
* <p>This abstract method should be implemented by subclasses to perform the GET operation,
74+
* which is used in benchmarking tests to measure performance metrics such as throughput and average execution time.</p>
75+
*/
76+
public abstract void testGet();
5877

59-
public abstract void testPut();
78+
/**
79+
* Executes a put operation for benchmarking purposes.
80+
*
81+
* <p>Implementations should override this method to define the logic for a put operation,
82+
* which will be measured by throughput and average execution time benchmarks.</p>
83+
*/
84+
public abstract void testPut();
6085

61-
public abstract void testAllOps();
86+
/**
87+
* Executes a comprehensive set of benchmark operations.
88+
*
89+
* <p>This abstract method should be implemented to perform a mixed workload—typically combining
90+
* get and put operations—to simulate a realistic full-spectrum scenario. It is invoked during
91+
* benchmarking runs to measure both throughput and average execution time in multi-threaded environments.
92+
*/
93+
public abstract void testAllOps();
6294
}

src/jmh/java/com/trivago/kangaroo/FastutilWrapperBusyWaitingBenchmark.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
@Warmup(iterations = 3, time = 1)
1313
@Measurement(iterations = 3, time = 2)
1414
public class FastutilWrapperBusyWaitingBenchmark extends AbstractBenchHelper {
15+
/**
16+
* Initializes and loads benchmark data using busy waiting mode.
17+
*
18+
* <p>This setup method is executed once per trial (as dictated by the @Setup(Level.Trial)
19+
* annotation) to prepare the data required for the benchmark.
20+
*/
1521
@Setup(Level.Trial)
1622
public void loadData() {
1723
initAndLoadData(PrimitiveMapBuilder.MapMode.BUSY_WAITING);

src/jmh/java/com/trivago/kangaroo/FastutilWrapperDefaultBenchmark.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
@Warmup(iterations = 3, time = 1)
1313
@Measurement(iterations = 3, time = 2)
1414
public class FastutilWrapperDefaultBenchmark extends AbstractBenchHelper {
15+
/**
16+
* Initializes and loads the data required for the benchmark trial in blocking mode.
17+
*
18+
* <p>
19+
* This method is executed once before the benchmark trial starts and sets up the necessary data by
20+
* invoking the initialization routine with the blocking mode specified by {@code PrimitiveMapBuilder.MapMode.BLOCKING}.
21+
* </p>
22+
*/
1523
@Setup(Level.Trial)
1624
public void loadData() {
1725
initAndLoadData(PrimitiveMapBuilder.MapMode.BLOCKING);

src/jmh/java/com/trivago/kangaroo/JavaUtilWrapperBenchmark.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
public class JavaUtilWrapperBenchmark extends AbstractCommonBenchHelper {
2222
Map<Long, Long> map;
2323

24+
/**
25+
* Initializes the benchmark map with random long key-value pairs.
26+
*
27+
* <p>This setup method creates a {@code Long2LongOpenHashMap} with a predefined capacity and a load factor of 0.8,
28+
* populates it with random long keys and values generated via {@code ThreadLocalRandom}, and then wraps the map with
29+
* {@code Collections.synchronizedMap} to ensure thread-safe access during benchmark trials.
30+
*
31+
* <p>The method is executed once per trial, as indicated by the {@code @Setup(Level.Trial)} annotation.
32+
*/
2433
@Setup(Level.Trial)
2534
public void loadData() {
2635
Long2LongOpenHashMap m = new Long2LongOpenHashMap(AbstractBenchHelper.NUM_VALUES, 0.8f);
@@ -32,19 +41,44 @@ public void loadData() {
3241
map = Collections.synchronizedMap(m);
3342
}
3443

44+
/**
45+
* Benchmarks a map retrieval operation using a randomly generated key.
46+
*
47+
* <p>This method generates a random key via {@link java.util.concurrent.ThreadLocalRandom}
48+
* and retrieves the corresponding value from the synchronized map. It is designed to measure
49+
* the performance of get operations during benchmarking tests.</p>
50+
*/
3551
@Override
3652
public void testGet() {
3753
long key = ThreadLocalRandom.current().nextLong();
3854
map.get(key);
3955
}
4056

57+
/**
58+
* Inserts a new entry into the map using randomly generated key and value.
59+
*
60+
* <p>This method generates random long values for both the key and value with
61+
* {@link ThreadLocalRandom} and inserts the entry into the synchronized map,
62+
* serving as a benchmark for put operations.</p>
63+
*/
4164
@Override
4265
public void testPut() {
4366
long key = ThreadLocalRandom.current().nextLong();
4467
long value = ThreadLocalRandom.current().nextLong();
4568
map.put(key, value);
4669
}
4770

71+
/**
72+
* Executes a randomly selected map operation for benchmarking purposes.
73+
*
74+
* <p>This method randomly performs one of three actions on the map:
75+
* <ul>
76+
* <li>Inserts a new key-value pair (put operation) when the random choice equals 1.</li>
77+
* <li>Removes an entry (remove operation) when the random choice equals 2.</li>
78+
* <li>Retrieves a value (get operation) for any other random choice.</li>
79+
* </ul>
80+
* This supports mixed operation workloads during benchmark tests.
81+
*/
4882
@Override
4983
public void testAllOps() {
5084
int op = ThreadLocalRandom.current().nextInt(3);

src/jmh/java/com/trivago/kangaroo/long2long/AbstractLongLongBenchHelper.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ public abstract class AbstractLongLongBenchHelper extends AbstractCommonBenchHel
1010
protected static final int NUM_VALUES = 1_000_000;
1111
protected ConcurrentLongLongMap map;
1212

13+
/**
14+
* Initializes the concurrent map with a fixed configuration and populates it with random key-value pairs.
15+
*
16+
* <p>The map is built with 16 buckets, an initial capacity of {@code NUM_VALUES} (1,000,000), and a load factor of 0.8.
17+
* The provided map mode is used during construction. After initialization, the map is filled with
18+
* {@code NUM_VALUES} randomly generated long key-value pairs.
19+
*
20+
* @param mode the map mode to be applied during the map's initialization
21+
*/
1322
public void initAndLoadData (PrimitiveMapBuilder.MapMode mode) {
1423
map = ConcurrentLongLongMap.newBuilder()
1524
.withBuckets(16)
@@ -25,19 +34,41 @@ public void initAndLoadData (PrimitiveMapBuilder.MapMode mode) {
2534
}
2635
}
2736

37+
/**
38+
* Retrieves a value from the concurrent map using a randomly generated key.
39+
*
40+
* <p>This benchmark method generates a random long key via ThreadLocalRandom and uses it to perform a
41+
* get operation on the map, facilitating the measurement of concurrent retrieval performance.</p>
42+
*/
2843
@Override
2944
public void testGet() {
3045
long key = ThreadLocalRandom.current().nextLong();
3146
map.get(key);
3247
}
3348

49+
/**
50+
* Benchmarks the put operation on the concurrent map by inserting a randomly generated key-value pair.
51+
*
52+
* <p>This method uses thread-local random values for both the key and value to simulate a put operation
53+
* in a concurrent benchmarking scenario.</p>
54+
*/
3455
@Override
3556
public void testPut() {
3657
long key = ThreadLocalRandom.current().nextLong();
3758
long value = ThreadLocalRandom.current().nextLong();
3859
map.put(key, value);
3960
}
4061

62+
/**
63+
* Executes a random operation on the concurrent map.
64+
*
65+
* <p>This method randomly selects one of three operations:
66+
* <ul>
67+
* <li>When the random value is 1, it inserts a new key-value pair into the map.</li>
68+
* <li>When the random value is 2, it removes the entry associated with a random key.</li>
69+
* <li>Otherwise, it retrieves the value of a random key.</li>
70+
* </ul>
71+
*/
4172
@Override
4273
public void testAllOps() {
4374
int op = ThreadLocalRandom.current().nextInt(3);

src/jmh/java/com/trivago/kangaroo/long2long/FastutilWrapperBusyWaitingLongLongBenchmark.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
@Warmup(iterations = 3, time = 1)
1313
@Measurement(iterations = 3, time = 2)
1414
public class FastutilWrapperBusyWaitingLongLongBenchmark extends AbstractLongLongBenchHelper {
15+
/**
16+
* Initializes and loads data in busy-waiting mode for the benchmark trial.
17+
*
18+
* <p>This method is executed once before the benchmark trial begins and sets up the data by
19+
* invoking the superclass's data initialization routine with a busy-waiting strategy.
20+
*/
1521
@Setup(Level.Trial)
1622
public void loadData() {
1723
initAndLoadData(PrimitiveMapBuilder.MapMode.BUSY_WAITING);

src/jmh/java/com/trivago/kangaroo/long2long/FastutilWrapperDefaultLongLongBenchmark.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
@Warmup(iterations = 3, time = 1)
1313
@Measurement(iterations = 3, time = 2)
1414
public class FastutilWrapperDefaultLongLongBenchmark extends AbstractLongLongBenchHelper {
15+
/**
16+
* Initializes and loads data for the benchmark trial.
17+
*
18+
* <p>This setup method is executed once before the benchmark trial begins. It initializes
19+
* the necessary data structures in blocking mode by invoking {@code initAndLoadData} with
20+
* {@code PrimitiveMapBuilder.MapMode.BLOCKING}.</p>
21+
*/
1522
@Setup(Level.Trial)
1623
public void loadData() {
1724
initAndLoadData(PrimitiveMapBuilder.MapMode.BLOCKING);

src/jmh/java/com/trivago/kangaroo/long2long/JavaConcurrentLongLongBenchmark.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ public class JavaConcurrentLongLongBenchmark extends AbstractCommonBenchHelper {
1919

2020
Map<Long, Long> map;
2121

22+
/**
23+
* Initializes the concurrent map with random key-value pairs for the benchmarking trial.
24+
*
25+
* <p>This setup method, annotated with {@code @Setup(Level.Trial)}, creates a {@link java.util.concurrent.ConcurrentHashMap}
26+
* using a predefined capacity and load factor, then populates it with entries where both keys and values are random long
27+
* values generated by {@link java.util.concurrent.ThreadLocalRandom}.
28+
*/
2229
@Setup(Level.Trial)
2330
public void loadData() {
2431
map = new ConcurrentHashMap<>(AbstractLongLongBenchHelper.NUM_VALUES, 0.8f);
@@ -29,19 +36,44 @@ public void loadData() {
2936
}
3037
}
3138

39+
/**
40+
* Benchmarks a get operation on the concurrent map by retrieving a value using a randomly generated key.
41+
*
42+
* <p>This method generates a random long key with ThreadLocalRandom and performs a lookup in the map,
43+
* serving as part of the benchmarking process for concurrent retrieval performance.
44+
*/
3245
@Override
3346
public void testGet() {
3447
long key = ThreadLocalRandom.current().nextLong();
3548
map.get(key);
3649
}
3750

51+
/**
52+
* Inserts a random key-value pair into the map.
53+
*
54+
* <p>This method generates random long values for both the key and the value using ThreadLocalRandom,
55+
* and inserts the generated pair into the map. It overrides the superclass method to simulate a put
56+
* operation within a concurrent benchmarking environment.
57+
*/
3858
@Override
3959
public void testPut() {
4060
long key = ThreadLocalRandom.current().nextLong();
4161
long value = ThreadLocalRandom.current().nextLong();
4262
map.put(key, value);
4363
}
4464

65+
/**
66+
* Executes a randomly selected operation on the concurrent map.
67+
*
68+
* <p>This method simulates mixed access patterns by performing one of three operations:
69+
* <ul>
70+
* <li>A put operation, inserting a new entry with random long key and value.</li>
71+
* <li>A remove operation, deleting an entry corresponding to a random long key.</li>
72+
* <li>A get operation, retrieving the value for a random long key.</li>
73+
* </ul>
74+
*
75+
* <p>These operations are used for concurrent benchmarking of map performance.
76+
*/
4577
@Override
4678
public void testAllOps() {
4779
int op = ThreadLocalRandom.current().nextInt(3);

src/jmh/java/com/trivago/kangaroo/long2long/JavaUtilWrapperLongLongBenchmark.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ public class JavaUtilWrapperLongLongBenchmark extends AbstractCommonBenchHelper
2020

2121
Map<Long, Long> map;
2222

23+
/**
24+
* Initializes the map with random long key-value pairs for benchmarking.
25+
*
26+
* <p>This method creates a Long2LongOpenHashMap with an initial capacity defined by
27+
* AbstractLongLongBenchHelper.NUM_VALUES and a load factor of 0.8, populating it with
28+
* randomly generated key-value pairs using ThreadLocalRandom. The generated map is then wrapped
29+
* in a synchronized map to ensure thread safety during benchmark operations. This setup is
30+
* executed once per trial as indicated by the @Setup(Level.Trial) annotation.</p>
31+
*/
2332
@Setup(Level.Trial)
2433
public void loadData() {
2534
Long2LongOpenHashMap m = new Long2LongOpenHashMap(AbstractLongLongBenchHelper.NUM_VALUES, 0.8f);
@@ -31,19 +40,43 @@ public void loadData() {
3140
map = Collections.synchronizedMap(m);
3241
}
3342

43+
/**
44+
* Benchmarks the retrieval of a value from the map using a randomly generated key.
45+
*
46+
* <p>This method generates a random key and retrieves the associated value from the map, helping to simulate
47+
* random access patterns during performance measurements.
48+
*/
3449
@Override
3550
public void testGet() {
3651
long key = ThreadLocalRandom.current().nextLong();
3752
map.get(key);
3853
}
3954

55+
/**
56+
* Inserts a random key-value pair into the map to benchmark the put operation.
57+
*
58+
* <p>This method generates random long values for both the key and the value using ThreadLocalRandom,
59+
* then adds the pair to the map.
60+
*/
4061
@Override
4162
public void testPut() {
4263
long key = ThreadLocalRandom.current().nextLong();
4364
long value = ThreadLocalRandom.current().nextLong();
4465
map.put(key, value);
4566
}
4667

68+
/**
69+
* Performs a random operation on the map.
70+
*
71+
* <p>This method randomly selects one of the following operations using a randomly generated key:
72+
* <ul>
73+
* <li>If the random operation equals 1, inserts a new key-value pair with a randomly generated value.</li>
74+
* <li>If the random operation equals 2, removes the entry associated with the key.</li>
75+
* <li>Otherwise, retrieves the value associated with the key.</li>
76+
* </ul>
77+
*
78+
* <p>The method does not return any value.
79+
*/
4780
@Override
4881
public void testAllOps() {
4982
int op = ThreadLocalRandom.current().nextInt(3);

0 commit comments

Comments
 (0)