Skip to content

Commit 9ff6b06

Browse files
author
Abduqodiri Qurbonzoda
committed
docs!: overhaul for accuracy and quality
1 parent 566d01c commit 9ff6b06

7 files changed

+437
-284
lines changed

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).

docs/interpreting-results.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ While analyzing benchmark results, watch out for these common pitfalls:
4848

4949
4. **Dead Code Elimination:** The JVM is very good at optimizing your code, and sometimes it can optimize your benchmark right out of existence! Make sure your benchmarks do real work and that their results are used somehow (often by returning them from the benchmark method), or else the JVM might optimize them away.
5050

51-
5. **Measurement error:** Ensure that you are not running any heavy processes in the background that could distort your benchmark results.
51+
5. **Measurement error:** Ensure that you are not running any heavy processes in the background that could distort your benchmark results.

0 commit comments

Comments
 (0)