From 5c5658252a92cfea9c9031db8dd5a49817bb2cee 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 | 9 +++++ .../jdk/benchmarks/LinkedHashMapBenchmark.kt | 25 ++++++++++++++ 4 files changed, 93 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..cb41bfef48 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,11 @@ open class StampedCacheBenchmark { get("1") {} get("2") {} } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + fun getEntries(input: StampedCacheInput) = input.largeCache.run { + get("1") { "" } + get("2") { "" } + } } 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 {