Skip to content

Commit ab24fc1

Browse files
committed
Update readme
1 parent 098822a commit ab24fc1

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

README.md

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
[![JetBrains incubator project](https://jb.gg/badges/incubator.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
22
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)
33

4-
# Setting up
4+
`kotlinx.benchmark` is a toolkit for running benchmarks for code written in Kotlin
5+
and supporting all supported targets: JVM, JavaScript and Native.
56

6-
Add repository in `settings.gradle` to enable my bintray repository for plugin lookup
7+
If you're familiar with [JMH](https://openjdk.java.net/projects/code-tools/jmh/), it is very similar and uses it under
8+
the hoods to run benchmarks on JVM.
9+
10+
# Gradle plugin
11+
12+
Add repository in `settings.gradle` to enable bintray repository for plugin lookup
713

814
```groovy
915
pluginManagement {
1016
repositories {
11-
maven { url 'https://dl.bintray.com/orangy/maven' }
17+
maven { url 'https://dl.bintray.com/kotlin/kotlinx' }
1218
gradlePluginPortal()
1319
}
1420
}
1521
```
1622

23+
TODO: This is not needed in latest Gradle versions.
1724
If you are using it for Kotlin Multiplatform, enable metadata in `settings.gradle`:
1825

1926
```groovy
2027
enableFeaturePreview('GRADLE_METADATA')
2128
```
2229

30+
TODO: Migrate to 1.3.40 node.js integrated support.
2331
For Kotlin/JS code, add Node plugin as well:
2432

2533
```groovy
@@ -32,34 +40,36 @@ node {
3240
}
3341
```
3442

35-
For Kotlin/JVM code, add `allopen` plugin to make JMH happy:
43+
For Kotlin/JVM code, add `allopen` plugin to make JMH happy. Alternatively, make all benchmark classes and methods `open`.
3644

3745
```groovy
3846
plugins {
39-
id 'org.jetbrains.kotlin.plugin.allopen' version "1.3.30"
47+
id 'org.jetbrains.kotlin.plugin.allopen' version "1.3.31"
4048
}
4149
4250
allOpen {
4351
annotation("org.openjdk.jmh.annotations.State")
4452
}
4553
```
4654

47-
# Adding multiplatform runtime library
55+
# Runtime Library
4856

49-
For JVM benchmarks you don't need anything, JMH core is added automatically.
50-
If you want to author multiplatform (especially common) benchmarks, you need a runtime library with small subset of
51-
annotations and code that will wire things up. The dependency is added automatically, but you need to add a repository
52-
so that Gradle can resolve this dependency.
57+
You need a runtime library with annotations and code that will run benchmarks on JavaScript and Native platforms.
5358

5459
```groovy
5560
repositories {
56-
maven { url 'https://dl.bintray.com/orangy/maven' }
61+
maven { url 'https://dl.bintray.com/kotlin/kotlinx' }
62+
}
63+
64+
dependencies {
65+
implementation "org.jetbrains.kotlinx:kotlinx.benchmark.runtime" version "0.2.0"
5766
}
5867
```
5968

60-
# Configuring benchmark targets
69+
# Configuration
6170

6271
In a `build.gradle` file create ` benchmark` section, and inside it add a `targets` section.
72+
In this section register all targets you want to run benchmarks from.
6373
Example for multiplatform project:
6474

6575
```groovy
@@ -82,17 +92,51 @@ benchmark {
8292
}
8393
```
8494

85-
Configure benchmarks:
95+
To configure benchmarks and create multiple profiles, create a `configurations` section in the `benchmark` block,
96+
and place options inside. Toolkit creates `main` configuration by default, and you can create as many additional
97+
configurations, as you need.
98+
99+
100+
```groovy
101+
benchmark {
102+
configurations {
103+
main {
104+
// configure default configuration
105+
}
106+
smoke {
107+
// create and configure "smoke" configuration, e.g. with several fast benchmarks to quickly check
108+
// if code changes result in something very wrong, or very right.
109+
}
110+
}
111+
}
112+
```
113+
114+
Available configuration options:
115+
116+
* `iterations` – number of measuring iterations
117+
* `warmups` – number of warm up iterations
118+
* `iterationTime` – time to run each iteration (measuring and warmup)
119+
* `iterationTimeUnit` – time unit for `iterationTime` (default is seconds)
120+
* `outputTimeUnit` – time unit for results output
121+
* `mode` – "thrpt" for measuring operations per time, or "avgt" for measuring time per operation
122+
* `include("…")` – regular expression to include benchmarks with fully qualified names matching it, as a substring
123+
* `exclude("…")` – regular expression to exclude benchmarks with fully qualified names matching it, as a substring
124+
* `param("name", "value1", "value2")` – specify a parameter for a public mutable property `name` annotated with `@Param`
125+
126+
Time units can be NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, or their short variants such as "ms" or "ns".
127+
128+
Example:
86129

87130
```groovy
88131
benchmark {
89132
// Create configurations
90133
configurations {
91134
main { // main configuration is created automatically, but you can change its defaults
135+
warmups = 20 // number of warmup iterations
92136
iterations = 10 // number of iterations
93137
iterationTime = 3 // time in seconds per iteration
94138
}
95-
fast {
139+
smoke {
96140
warmups = 5 // number of warmup iterations
97141
iterations = 3 // number of iterations
98142
iterationTime = 500 // time in seconds per iteration
@@ -113,8 +157,8 @@ benchmark {
113157
register("native")
114158
}
115159
}
116-
```
117-
160+
```
161+
118162
# Separate source sets for benchmarks
119163

120164
Often you want to have benchmarks in the same project, but separated from main code, much like tests. Here is how:

0 commit comments

Comments
 (0)