-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from CharlieTap/kotlinx-benchmark
Kotlinx Benchmark
- Loading branch information
Showing
9 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Benchmark ⌛ | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
runner: | ||
type: string | ||
description: 'The machine runner the workflow should run on' | ||
default: macos-latest | ||
required: false | ||
workflow_dispatch: | ||
inputs: | ||
runner: | ||
type: string | ||
description: 'The machine runner the workflow should run on' | ||
default: macos-latest | ||
required: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ inputs.runner }} | ||
steps: | ||
|
||
- name: Clone Repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up jdk@21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'corretto' | ||
java-version: '21' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Execute Gradle build | ||
run: ./gradlew benchmark | ||
|
||
- name: Move benchmark files | ||
run: | | ||
mkdir -p benchmark # This command ensures that the 'benchmark' directory exists | ||
find . -type f \( -iname '*benchmark.json' -o -iname '*benchmark.csv' \) -exec mv {} ./benchmark/ \; | ||
- name: Commit benchmark files | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add benchmark/*.{json,csv} | ||
git commit -m "Commit benchmark results" -a | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- 'benchmark/**' | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
cachemap/src/jvmBenchmark/kotlin/com/tap/cachemap/benchmark/BenchmarkConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.tap.cachemap.benchmark | ||
|
||
object BenchmarkConfig { | ||
const val WARMUP_ITERATIONS = 10 | ||
const val MEASUREMENT_ITERATIONS = 10 | ||
const val FORKS = 10 | ||
} |
6 changes: 6 additions & 0 deletions
6
...emap/src/jvmBenchmark/kotlin/com/tap/cachemap/benchmark/CacheMapMultiThreadedBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.tap.cachemap.benchmark | ||
|
||
import org.openjdk.jmh.annotations.Threads | ||
|
||
@Threads(Threads.MAX) | ||
class CacheMapMultiThreadedBenchmark : CacheMapSingleThreadBenchmark() |
89 changes: 89 additions & 0 deletions
89
cachemap/src/jvmBenchmark/kotlin/com/tap/cachemap/benchmark/CacheMapSingleThreadBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.tap.cachemap.benchmark | ||
import com.tap.cachemap.cacheMapOf | ||
import org.openjdk.jmh.annotations.Benchmark | ||
import org.openjdk.jmh.annotations.BenchmarkMode | ||
import org.openjdk.jmh.annotations.Fork | ||
import org.openjdk.jmh.annotations.Measurement | ||
import org.openjdk.jmh.annotations.Mode | ||
import org.openjdk.jmh.annotations.OutputTimeUnit | ||
import org.openjdk.jmh.annotations.Scope | ||
import org.openjdk.jmh.annotations.Setup | ||
import org.openjdk.jmh.annotations.State | ||
import org.openjdk.jmh.annotations.TearDown | ||
import org.openjdk.jmh.annotations.Warmup | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@State(Scope.Benchmark) | ||
@Fork(value = BenchmarkConfig.FORKS) | ||
@BenchmarkMode(Mode.AverageTime, Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Warmup(iterations = BenchmarkConfig.WARMUP_ITERATIONS, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = BenchmarkConfig.MEASUREMENT_ITERATIONS, time = 1, timeUnit = TimeUnit.SECONDS) | ||
class CacheMapSingleThreadBenchmark { | ||
|
||
private val cacheMap = cacheMapOf<String, String>() | ||
|
||
@Setup | ||
fun setup() { | ||
for (i in 1..1000) { | ||
cacheMap.put("key$i", "value$i") | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun put(blackhole: Blackhole) { | ||
val result = cacheMap.put("Hello", "World") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun overwrite(blackhole: Blackhole) { | ||
val result = cacheMap.put("key1", "value2") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun putAll(blackhole: Blackhole) { | ||
val anotherMap = mapOf("Hello" to "World", "SecondKey" to "SecondValue") | ||
val result = cacheMap.putAll(anotherMap) | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun get(blackhole: Blackhole) { | ||
val result: String? = cacheMap["key1"] | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun getMiss(blackhole: Blackhole) { | ||
val result: String? = cacheMap["Hello"] | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun remove(blackhole: Blackhole) { | ||
val result = cacheMap.remove("key1") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun stressTest(blackhole: Blackhole) { | ||
for (i in 1..1000) { | ||
val putResult = cacheMap.put("newKey$i", "newValue$i") | ||
blackhole.consume(putResult) | ||
|
||
val getResult: String? = cacheMap["key$i"] | ||
blackhole.consume(getResult) | ||
|
||
val removeResult = cacheMap.remove("newKey$i") | ||
blackhole.consume(removeResult) | ||
} | ||
} | ||
|
||
@TearDown | ||
fun tearDown() { | ||
cacheMap.clear() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...jvmBenchmark/kotlin/com/tap/cachemap/benchmark/ConcurrentHashMapMultiThreadedBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.tap.cachemap.benchmark | ||
|
||
import org.openjdk.jmh.annotations.Threads | ||
|
||
@Threads(Threads.MAX) | ||
class ConcurrentHashMapMultiThreadedBenchmark : ConcurrentHashMapSingleThreadedBenchmark() |
90 changes: 90 additions & 0 deletions
90
...vmBenchmark/kotlin/com/tap/cachemap/benchmark/ConcurrentHashMapSingleThreadedBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.tap.cachemap.benchmark | ||
|
||
import org.openjdk.jmh.annotations.Benchmark | ||
import org.openjdk.jmh.annotations.BenchmarkMode | ||
import org.openjdk.jmh.annotations.Fork | ||
import org.openjdk.jmh.annotations.Measurement | ||
import org.openjdk.jmh.annotations.Mode | ||
import org.openjdk.jmh.annotations.OutputTimeUnit | ||
import org.openjdk.jmh.annotations.Scope | ||
import org.openjdk.jmh.annotations.Setup | ||
import org.openjdk.jmh.annotations.State | ||
import org.openjdk.jmh.annotations.TearDown | ||
import org.openjdk.jmh.annotations.Warmup | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.ConcurrentHashMap | ||
import java.util.concurrent.TimeUnit | ||
|
||
@State(Scope.Benchmark) | ||
@Fork(value = BenchmarkConfig.FORKS) | ||
@BenchmarkMode(Mode.AverageTime, Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Warmup(iterations = BenchmarkConfig.WARMUP_ITERATIONS, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@Measurement(iterations = BenchmarkConfig.MEASUREMENT_ITERATIONS, time = 1, timeUnit = TimeUnit.SECONDS) | ||
class ConcurrentHashMapSingleThreadedBenchmark { | ||
|
||
private val cacheMap = ConcurrentHashMap<String, String>() | ||
|
||
@Setup | ||
fun setup() { | ||
for (i in 1..1000) { | ||
cacheMap["key$i"] = "value$i" | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun put(blackhole: Blackhole) { | ||
val result = cacheMap.put("Hello", "World") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun overwrite(blackhole: Blackhole) { | ||
val result = cacheMap.put("key1", "value2") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun putAll(blackhole: Blackhole) { | ||
val anotherMap = mapOf("Hello" to "World", "SecondKey" to "SecondValue") | ||
cacheMap.putAll(anotherMap) | ||
blackhole.consume(anotherMap) | ||
} | ||
|
||
@Benchmark | ||
fun get(blackhole: Blackhole) { | ||
val result: String? = cacheMap["key1"] | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun getMiss(blackhole: Blackhole) { | ||
val result: String? = cacheMap["Hello"] | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun remove(blackhole: Blackhole) { | ||
val result = cacheMap.remove("key1") | ||
blackhole.consume(result) | ||
} | ||
|
||
@Benchmark | ||
fun stressTest(blackhole: Blackhole) { | ||
for (i in 1..1000) { | ||
val putResult = cacheMap.put("newKey$i", "newValue$i") | ||
blackhole.consume(putResult) | ||
|
||
val getResult: String? = cacheMap["key$i"] | ||
blackhole.consume(getResult) | ||
|
||
val removeResult = cacheMap.remove("newKey$i") | ||
blackhole.consume(removeResult) | ||
} | ||
} | ||
|
||
@TearDown | ||
fun tearDown() { | ||
cacheMap.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters