New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JMH benchmark setup #763
Closed
Closed
JMH benchmark setup #763
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,29 @@ | ||
This is a performance testing setup for `mockk` using [JMH](https://github.com/openjdk/jmh). [kotlinx-benchmark](https://github.com/Kotlin/kotlinx-benchmark) seems to support more than JVM, but I didn't explore other runtimes. | ||
|
||
How to run | ||
========== | ||
There are 2 ways to execute the benchmark code | ||
|
||
Basic with Gradle | ||
----------------- | ||
|
||
```shell | ||
gradle benchmark | ||
``` | ||
It will use default configuration set in [build.gradle.kts](./build.gradle.kts) and print | ||
out the results | ||
|
||
Advanced with JMH binary | ||
------------------------ | ||
|
||
If you want access to more JMH feautres you can | ||
```shell | ||
gradle mainBenchmarkJar | ||
``` | ||
to build the `.jar` file containing the benchamrk code. It will be saved to `./build/benchmarks/main/jars` directory. | ||
|
||
From there you can run JMH with all the JMH-specific configuration options form CLI (even on different machine). | ||
```shell | ||
java -jar ./build/benchmarks/main/jars/mockk-performance-main-jmh-<version>.jar -w 1 -i 2 -r 60s -prof jfr | ||
``` | ||
which will e.g. attach the JFR profiler (not possible with `kontlinx-benchmark` executed from Gradle) |
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,32 @@ | ||
import kotlinx.benchmark.gradle.JvmBenchmarkTarget | ||
import kotlinx.benchmark.gradle.benchmark | ||
|
||
plugins { | ||
java | ||
kotlin("jvm") | ||
id("org.jetbrains.kotlinx.benchmark") version "0.4.0" | ||
|
||
} | ||
|
||
dependencies { | ||
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.0") | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") | ||
implementation(project(":mockk-jvm")) | ||
} | ||
|
||
benchmark { | ||
configurations { | ||
named("main") { | ||
iterationTime = 60 | ||
iterationTimeUnit = "sec" | ||
iterations = 2 | ||
warmups = 1 | ||
} | ||
} | ||
targets { | ||
register("main") { | ||
this as JvmBenchmarkTarget | ||
jmhVersion = "1.33" | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
mockk/performance/src/main/kotlin/io/mockk/performance/JmhTest.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,23 @@ | ||
package io.mockk.performance | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.openjdk.jmh.annotations.Benchmark | ||
import org.openjdk.jmh.annotations.BenchmarkMode | ||
import org.openjdk.jmh.annotations.Mode | ||
import org.openjdk.jmh.infra.Blackhole | ||
|
||
@BenchmarkMode(Mode.Throughput) | ||
open class JmhTest { | ||
|
||
@Benchmark | ||
fun simpleMockAndStub(blackhole: Blackhole) { | ||
val mockedClass: MockedClass = mockk() | ||
every { mockedClass.mockedFun() } returns "Hello, mockk!" | ||
blackhole.consume(mockedClass) | ||
} | ||
|
||
class MockedClass { | ||
fun mockedFun(): String = "Hello, world!" | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should stay commented (or even better removed), because the kotlin version is being set externally by the github action that runs the builds for several different versions.
It's likely the reason why builds on 1.3.* fail.