From 822321e285fb8d15f57f2390b593e51f928879a9 Mon Sep 17 00:00:00 2001 From: "Kenneth J. Shackleton" Date: Sat, 22 Jun 2024 17:19:01 +0100 Subject: [PATCH] More large cache benchmarks. --- .../benchmarks/CommonLruCacheBenchmark.kt | 34 +++++++++++++++++++ .../benchmarks/LinkedLruCacheBenchmark.kt | 25 ++++++++++++++ .../cache/benchmarks/StampedCacheBenchmark.kt | 34 +++++++++++++++++++ .../FastLinkedStringMapBenchmark.kt | 25 ++++++++++++++ .../FastStampedStringMapBenchmark.kt | 27 +++++++++++++++ .../jdk/benchmarks/LinkedHashMapBenchmark.kt | 25 ++++++++++++++ 6 files changed, 170 insertions(+) diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/CommonLruCacheBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/CommonLruCacheBenchmark.kt index 711cee5d86..fd1f0e503c 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/CommonLruCacheBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/CommonLruCacheBenchmark.kt @@ -28,10 +28,12 @@ import org.openjdk.jmh.annotations.State @State(Scope.Thread) open class CommonCacheInput { internal lateinit var cache: CommonLruCache + internal lateinit var largeCache: CommonLruCache @Setup(Level.Iteration) fun setUp() { cache = CommonLruCache(1) {} + largeCache = CommonLruCache(64) {} } } @@ -48,4 +50,36 @@ open class CommonLruCacheBenchmark { get("1") {} get("2") {} } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getEntries(input: CommonCacheInput) = input.largeCache.run { + get("1") { "" } + get("2") { "" } + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getManyEntries(input: CommonCacheInput) = input.largeCache.run { + get("0") { "" } + get("1") { "" } + get("2") { "" } + get("3") { "" } + get("4") { "" } + get("5") { "" } + get("6") { "" } + get("7") { "" } + get("8") { "" } + get("9") { "" } + get("2") { "" } + get("3") { "" } + get("9") { "" } + get("4") { "" } + get("5") { "" } + get("0") { "" } + get("8") { "" } + get("6") { "" } + get("1") { "" } + get("7") { "" } + } } diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/LinkedLruCacheBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/LinkedLruCacheBenchmark.kt index be0093f9d9..12c75f3114 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/LinkedLruCacheBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/LinkedLruCacheBenchmark.kt @@ -57,4 +57,29 @@ open class LinkedLruCacheBenchmark { get("1") { "" } get("2") { "" } } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getManyEntries(input: LinkedCacheInput) = input.largeCache.run { + get("0") { "" } + get("1") { "" } + get("2") { "" } + get("3") { "" } + get("4") { "" } + get("5") { "" } + get("6") { "" } + get("7") { "" } + get("8") { "" } + get("9") { "" } + get("2") { "" } + get("3") { "" } + get("9") { "" } + get("4") { "" } + get("5") { "" } + get("0") { "" } + get("8") { "" } + get("6") { "" } + get("1") { "" } + get("7") { "" } + } } diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/StampedCacheBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/StampedCacheBenchmark.kt index 91d5176ebe..6ac71c3ca6 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/StampedCacheBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/cache/benchmarks/StampedCacheBenchmark.kt @@ -28,10 +28,12 @@ import org.openjdk.jmh.annotations.State @State(Scope.Thread) open class StampedCacheInput { internal lateinit var cache: StampedCache + internal lateinit var largeCache: StampedCache @Setup(Level.Iteration) fun setUp() { cache = StampedCache(1) {} + largeCache = StampedCache(64) {} } } @@ -48,4 +50,36 @@ open class StampedCacheBenchmark { get("1") {} get("2") {} } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getEntries(input: StampedCacheInput) = input.largeCache.run { + get("1") { "" } + get("2") { "" } + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getManyEntries(input: StampedCacheInput) = input.largeCache.run { + get("0") { "" } + get("1") { "" } + get("2") { "" } + get("3") { "" } + get("4") { "" } + get("5") { "" } + get("6") { "" } + get("7") { "" } + get("8") { "" } + get("9") { "" } + get("2") { "" } + get("3") { "" } + get("9") { "" } + get("4") { "" } + get("5") { "" } + get("0") { "" } + get("8") { "" } + get("6") { "" } + get("1") { "" } + get("7") { "" } + } } diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastLinkedStringMapBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastLinkedStringMapBenchmark.kt index 89e0e9ea7f..bbf52a22a3 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastLinkedStringMapBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastLinkedStringMapBenchmark.kt @@ -94,4 +94,29 @@ open class FastLinkedStringMapBenchmark { getElsePut("1") { "" } removeKey("1") } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getManyEntriesAccessOrder(input: LinkedMapInput) = input.largeAccessMap.run { + getEntryElsePut("0") { "" } + getEntryElsePut("1") { "" } + getEntryElsePut("2") { "" } + getEntryElsePut("3") { "" } + getEntryElsePut("4") { "" } + getEntryElsePut("5") { "" } + getEntryElsePut("6") { "" } + getEntryElsePut("7") { "" } + getEntryElsePut("8") { "" } + getEntryElsePut("9") { "" } + getEntryElsePut("2") { "" } + getEntryElsePut("3") { "" } + getEntryElsePut("9") { "" } + getEntryElsePut("4") { "" } + getEntryElsePut("5") { "" } + getEntryElsePut("0") { "" } + getEntryElsePut("8") { "" } + getEntryElsePut("6") { "" } + getEntryElsePut("1") { "" } + getEntryElsePut("7") { "" } + } } diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastStampedStringMapBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastStampedStringMapBenchmark.kt index cce9d1cc4a..32b4e166e8 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastStampedStringMapBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/collections/map/benchmarks/FastStampedStringMapBenchmark.kt @@ -28,10 +28,12 @@ import org.openjdk.jmh.annotations.State @State(Scope.Thread) open class StampedMapInput { internal lateinit var map: FastStampedStringMap + internal lateinit var largeMap: FastStampedStringMap @Setup(Level.Iteration) fun setUp() { map = FastStampedStringMap(1) {} + largeMap = FastStampedStringMap(64) {} } } @@ -55,4 +57,29 @@ open class FastStampedStringMapBenchmark { getEntryElsePut("1") { "" } removeEntry("1") } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getManyEntries(input: StampedMapInput) = input.largeMap.run { + getEntryElsePut("0") { "" } + getEntryElsePut("1") { "" } + getEntryElsePut("2") { "" } + getEntryElsePut("3") { "" } + getEntryElsePut("4") { "" } + getEntryElsePut("5") { "" } + getEntryElsePut("6") { "" } + getEntryElsePut("7") { "" } + getEntryElsePut("8") { "" } + getEntryElsePut("9") { "" } + getEntryElsePut("2") { "" } + getEntryElsePut("3") { "" } + getEntryElsePut("9") { "" } + getEntryElsePut("4") { "" } + getEntryElsePut("5") { "" } + getEntryElsePut("0") { "" } + getEntryElsePut("8") { "" } + getEntryElsePut("6") { "" } + getEntryElsePut("1") { "" } + getEntryElsePut("7") { "" } + } } diff --git a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/jdk/benchmarks/LinkedHashMapBenchmark.kt b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/jdk/benchmarks/LinkedHashMapBenchmark.kt index 9b4d3ec210..fd9b715f2d 100644 --- a/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/jdk/benchmarks/LinkedHashMapBenchmark.kt +++ b/selekt-java/src/jmh/kotlin/com/bloomberg/selekt/jdk/benchmarks/LinkedHashMapBenchmark.kt @@ -72,6 +72,31 @@ open class LinkedHashMapBenchmark { getOrPut("2") { "" } } + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getManyEntriesAccessOrder(input: LinkedHashMapInput) = input.largeAccessOrderMap.run { + getOrPut("0") { "" } + getOrPut("1") { "" } + getOrPut("2") { "" } + getOrPut("3") { "" } + getOrPut("4") { "" } + getOrPut("5") { "" } + getOrPut("6") { "" } + getOrPut("7") { "" } + getOrPut("8") { "" } + getOrPut("9") { "" } + getOrPut("2") { "" } + getOrPut("3") { "" } + getOrPut("9") { "" } + getOrPut("4") { "" } + getOrPut("5") { "" } + getOrPut("0") { "" } + getOrPut("8") { "" } + getOrPut("6") { "" } + getOrPut("1") { "" } + getOrPut("7") { "" } + } + @Benchmark @BenchmarkMode(Mode.Throughput) fun getEntryWithRemoval(input: LinkedHashMapInput) = input.smallMap.run {