|
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) |
2 | 7 |
|
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 |
4 | 9 |
|
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. |
6 | 11 |
|
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. |
10 | 14 |
|
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. |
12 | 16 |
|
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. |
14 | 19 |
|
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. |
16 | 21 |
|
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. |
18 | 24 |
|
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. |
20 | 27 |
|
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. |
0 commit comments