Skip to content

Commit c26f523

Browse files
wldehqurbonzoda
authored andcommitted
docs!: overhaul for accuracy and quality
1 parent 05d8089 commit c26f523

10 files changed

+520
-449
lines changed

README.md

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,15 @@ The `kotlinx-benchmark` library is designed to work with Kotlin/JVM, Kotlin/JS,
5353
<details open>
5454
<summary>Kotlin DSL</summary>
5555

56-
1. **Adding Dependency**: Add the `kotlinx-benchmark-runtime` dependency in your `build.gradle.kts` file.
57-
58-
```kotlin
59-
dependencies {
60-
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.8")
61-
}
62-
```
63-
64-
2. **Applying Benchmark Plugin**: Next, apply the benchmark plugin.
56+
1. **Applying Benchmark Plugin**: Apply the benchmark plugin.
6557

6658
```kotlin
6759
plugins {
68-
id("org.jetbrains.kotlinx.benchmark") version "0.4.8"
60+
id("org.jetbrains.kotlinx.benchmark") version "0.4.9"
6961
}
7062
```
7163

72-
3. **Specifying Repository**: Ensure you have `mavenCentral()` for dependencies lookup in the list of repositories:
64+
2. **Specifying Repository**: Ensure you have `mavenCentral()` for dependencies lookup in the list of repositories:
7365

7466
```kotlin
7567
repositories {
@@ -82,24 +74,16 @@ The `kotlinx-benchmark` library is designed to work with Kotlin/JVM, Kotlin/JS,
8274
<details>
8375
<summary>Groovy DSL</summary>
8476

85-
1. **Adding Dependency**: In your `build.gradle` file, include the `kotlinx-benchmark-runtime` dependency.
86-
87-
```groovy
88-
dependencies {
89-
implementation 'org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.8'
90-
}
91-
```
92-
93-
2. **Applying Benchmark Plugin**: Next, apply the benchmark plugin.
77+
1. **Applying Benchmark Plugin**: Apply the benchmark plugin.
9478

9579
```groovy
9680
plugins {
9781
id 'org.jetbrains.kotlin.plugin.allopen' version "1.8.21"
98-
id 'org.jetbrains.kotlinx.benchmark' version '0.4.8'
82+
id 'org.jetbrains.kotlinx.benchmark' version '0.4.9'
9983
}
10084
```
10185

102-
3. **Specifying Repository**: Ensure you have `mavenCentral()` in the list of repositories:
86+
2. **Specifying Repository**: Ensure you have `mavenCentral()` in the list of repositories:
10387

10488
```groovy
10589
repositories {
@@ -163,42 +147,26 @@ This configuration ensures that your `MyBenchmark` class and its `benchmarkMetho
163147

164148
You can alternatively mark your benchmark classes and methods `open` manually, but using the `allopen` plugin enhances code maintainability. For a practical example, please refer to [examples](examples/kotlin-kts).
165149

166-
#### Java
167-
168-
In order to conduct benchmarking in Java, you need to apply the Java plugin.
169-
170-
```kotlin
171-
plugins {
172-
id("java")
173-
}
174-
```
175-
176-
For a practical example, please refer to [examples](examples/java).
177-
178150
#### Kotlin/JS
179151

180-
For benchmarking Kotlin/JS code Node.js execution enviroment should be targeted. See https://kotlinlang.org/docs/js-project-setup.html#execution-environments. This is because kotlinx-benchmark-runtime uses Node.js environment to run benchmarks. Include the `nodejs()` method call in the `kotlin` block:
181-
152+
Specify a compiler like the [IR compiler](https://kotlinlang.org/docs/js-ir-compiler.html) and set benchmarking targets in one step. Here, `jsIr` and `jsIrBuiltIn` are both using the IR compiler. The former uses benchmark.js, while the latter uses Kotlin's built-in plugin.
182153

183154
```kotlin
184155
kotlin {
185-
js {
186-
nodejs()
156+
js('jsIr', IR) {
157+
nodejs()
158+
}
159+
js('jsIrBuiltIn', IR) {
160+
nodejs()
187161
}
188162
}
189163
```
190164

191-
For Kotlin/JS, only IR backend is supported. For more information on the IR compiler, please refer to the [Kotlin/JS IR compiler documentation](https://kotlinlang.org/docs/js-ir-compiler.html)
192-
193165
#### Multiplatform
194166

195-
For multiplatform projects, add the `kotlinx-benchmark-runtime` dependency to the `commonMain` source set, and be sure to apply the multiplatform plugin, as shown below:
167+
For multiplatform projects, add the `kotlinx-benchmark-runtime` dependency to the `commonMain` source set:
196168

197169
```kotlin
198-
plugins {
199-
id("multiplatform")
200-
}
201-
202170
kotlin {
203171
sourceSets {
204172
commonMain {

docs/benchmark-runtime.md

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,28 @@
1-
# kotlinx.benchmark: A Comprehensive Guide to Benchmark Runtime for Each Target
1+
# Table of Contents
2+
1. [Introduction](#Understanding-Benchmark-Runtime-Across-Targets)
3+
2. [JVM: Harnessing JMH](#jvm-harnessing-jmh)
4+
3. [JavaScript: Benchmark.js Integration and In-built Support](#javascript-benchmarkjs-integration-and-in-built-support)
5+
4. [Native: Harnessing Native Capabilities](#native-harnessing-native-capabilities)
6+
5. [WebAssembly (Wasm): Custom-Built Benchmarking](#webassembly-wasm-custom-built-benchmarking)
27

3-
This document provides an in-depth overview of the kotlinx.benchmark library, focusing on how the benchmark runtime works for each supported target: JVM, JavaScript, and Native. This guide is designed for beginners and intermediates, providing a clear understanding of the underlying libraries used and the benchmark execution process.
8+
# Understanding Benchmark Runtime Across Targets
49

5-
## Table of Contents
10+
This comprehensive guide aims to shed light on the underlying libraries that Kotlinx Benchmark utilizes to measure performance on these platforms, and elucidate the benchmark runtime process.
611

7-
- [JVM Target](#jvm-target)
8-
- [JavaScript Target](#javascript-target)
9-
- [Native Target](#native-target)
12+
## JVM: Harnessing JMH
13+
In the JVM ecosystem, Kotlinx Benchmark capitalizes on the Java microbenchmarking harness [JMH](https://openjdk.org/projects/code-tools/jmh/). Designed by OpenJDK, JMH is a well-respected tool for creating, executing, and scrutinizing nano/micro/milli/macro benchmarks composed in Java and other JVM-compatible languages.
1014

11-
## JVM Target
15+
Kotlinx Benchmark complements JMH with an array of advanced features that fine-tune JVM-specific settings. An exemplary feature is the handling of 'forks', a mechanism that facilitates running multiple tests in distinct JVM processes. By doing so, it assures a pristine environment for each test, enhancing the reliability of the benchmark results. Moreover, its sophisticated error and exception handling system ensures that any issues arising during testing are logged and addressed.
1216

13-
The JVM target in kotlinx.benchmark leverages the Java Microbenchmark Harness (JMH) to run benchmarks. JMH is a widely-used tool for building, running, and analyzing benchmarks written in Java and other JVM languages.
17+
## JavaScript: Benchmark.js Integration and In-built Support
18+
Targeting JavaScript, Kotlinx Benchmark utilizes the `benchmark.js` library to measure performance. Catering to both synchronous and asynchronous benchmarks, this library enables evaluation of a vast array of JavaScript operations. `benchmark.js` operates by setting up a suite of benchmarks, where each benchmark corresponds to a distinct JavaScript operation to be evaluated.
1419

15-
### Benchmark Execution
20+
It's noteworthy that, alongside `benchmark.js`, Kotlinx Benchmark also incorporates its own built-in yet somewhat limited benchmarking system for Kotlin/JavaScript runtime.
1621

17-
JMH handles the execution of benchmarks, managing the setup, running, and teardown of tests. It also handles the calculation of results, providing a robust and reliable framework for benchmarking on the JVM.
22+
## Native: Harnessing Native Capabilities
23+
For Native platforms, Kotlinx Benchmark resorts to its built-in benchmarking system, which is firmly rooted in platform-specific technologies. Benchmarks are defined in the form of suites, each representing a specific Kotlin/Native operation to be evaluated.
1824

19-
### Benchmark Configuration
25+
## WebAssembly (Wasm): Custom-Built Benchmarking
26+
For Kotlin code running on WebAssembly (Wasm), Kotlinx Benchmark deploys built-in mechanisms to establish a testing milieu and measure code performance.
2027

21-
The benchmark configuration is handled through annotations that map directly to JMH annotations. These include `@State`, `@Benchmark`, `@BenchmarkMode`, `@OutputTimeUnit`, `@Warmup`, `@Measurement`, and `@Param`.
22-
23-
### File Operations
24-
25-
File reading and writing operations are performed using standard Java I/O classes, providing a consistent and reliable method for file operations across all JVM platforms.
26-
27-
## JavaScript Target
28-
29-
The JavaScript target in kotlinx.benchmark leverages the Benchmark.js library to run benchmarks. Benchmark.js is a robust tool for executing JavaScript benchmarks in different environments, including browsers and Node.js.
30-
31-
### Benchmark Execution
32-
33-
Benchmark.js handles the execution of benchmarks, managing the setup, running, and teardown of tests. Just like JMH for JVM, it also handles the calculation of results, providing a reliable framework for benchmarking on JavaScript.
34-
35-
### Benchmark Configuration
36-
37-
The benchmark configuration in JavaScript is handled through a suite and benchmark API provided by benchmark.js. The API allows the users to specify the details of the benchmark such as the function to benchmark, setup function, and teardown function.
38-
39-
### File Operations
40-
41-
File reading and writing operations in JavaScript are performed using the standard JavaScript file I/O APIs. This includes the fs module in Node.js or the File API in browsers.
42-
43-
## Native Target
44-
45-
The Native target in kotlinx.benchmark leverages the built-in benchmarking capabilities of the Kotlin/Native runtime to execute benchmarks.
46-
47-
### Benchmark Execution
48-
49-
Kotlin/Native manages the execution of benchmarks, handling the setup, running, and teardown of tests. Just like JMH for JVM and Benchmark.js for JavaScript, Kotlin/Native also takes care of the calculation of results, providing a reliable framework for benchmarking in a native environment.
50-
51-
### Benchmark Configuration
52-
53-
The benchmark configuration in Kotlin/Native is handled through annotations that are similar to those used in the JVM target. These include `@State`, `@Benchmark`, `@BenchmarkMode`, `@OutputTimeUnit`, `@Warmup`, `@Measurement`, and `@Param`.
54-
55-
### File Operations
56-
57-
File operations in the Native target are handled through Kotlin's standard file I/O APIs. These APIs are compatible with all platforms supported by Kotlin/Native, providing a consistent method for file operations.
28+
In this setup, similarly a suite of benchmarks is created, each pinpointing a different code segment. The execution time of each benchmark is gauged using high-resolution JavaScript functions, thereby providing accurate and precise performance measurements.

docs/benchmarking-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ While kotlinx-benchmark is geared towards microbenchmarking — typically examin
131131

132132
If you'd like to dig deeper into the world of benchmarking, here are some resources to help you on your journey:
133133

134-
- [Mastering High Performance with Kotlin](https://www.amazon.com/Mastering-High-Performance-Kotlin-difficulties/dp/178899664X)
134+
- [Mastering High Performance with Kotlin](https://www.amazon.com/Mastering-High-Performance-Kotlin-difficulties/dp/178899664X)

docs/compatibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ This guide provides you with information on the compatibility of different versi
1818

1919
*Note: "Minimum Required" implies that any higher version than the one mentioned will also be compatible.*
2020

21-
For more details about the changes, improvements, and updates in each `kotlinx-benchmark` version, please refer to the [RELEASE NOTES](https://github.com/Kotlin/kotlinx-benchmark/releases) and [CHANGELOG](../CHANGELOG.md).
21+
For more details about the changes, improvements, and updates in each `kotlinx-benchmark` version, please refer to the [RELEASE NOTES](https://github.com/Kotlin/kotlinx-benchmark/releases) and [CHANGELOG](../CHANGELOG.md).

0 commit comments

Comments
 (0)