Skip to content

Commit 2cddb7d

Browse files
authored
Add Kotlin script for running benchmarks for all targets (#5566)
The `run_benchmarks.main.kts` script provides running benchmarks on all supported platforms (macos, desktop, web, ios). It handles platform-specific details like starting a background server for web benchmarks or invoking iOS-specific scripts. Also it handles running benchmarks in a separate process. `compare_benchmarks.main.kts` and `find_degradations.main.kts` was also updated to use the script. Fixes [CMP-8273](https://youtrack.jetbrains.com/issue/CMP-8273) ## Release Notes N/A
1 parent ed489b5 commit 2cddb7d

6 files changed

Lines changed: 518 additions & 212 deletions

File tree

benchmarks/multiplatform/README.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,61 @@ You can configure benchmark runs using arguments passed to the Gradle task (via
4343
./gradlew :benchmarks:run -PrunArguments="benchmarks=LazyGrid modes=REAL frameCount=200"
4444
```
4545

46+
## Running Benchmarks via Scripts
47+
48+
There are several scripts provided to run benchmarks more conveniently, especially when you need to run multiple iterations or compare different versions.
49+
50+
### `run_benchmarks.main.kts`
51+
52+
This script is the main entry point for running benchmarks on all supported platforms (macos, desktop, web, ios). It handles platform-specific details like starting a background server for web benchmarks or invoking iOS-specific scripts.
53+
54+
**Usage:**
55+
```bash
56+
./run_benchmarks.main.kts <platform> [runs=1] [benchmarks=<benchmarkName>] [version=<version>] [separateProcess=true|false] [any other gradle args]
57+
```
58+
59+
**Platforms:** `macos`, `desktop`, `web`, `ios`
60+
61+
**Arguments:**
62+
- `runs=<number>`: Number of iterations to run (default: 1).
63+
- `benchmarks=<name1,name2,...>`: Filter benchmarks to run.
64+
- `version=<version>`: Compose Multiplatform version to use. If specified, the script updates `gradle/libs.versions.toml` before running and restores it afterward.
65+
- `separateProcess=true`: Runs each benchmark in a separate process for better isolation (default: `false`).
66+
- Any other arguments (e.g., `modes=SIMPLE`) are forwarded to the benchmark execution.
67+
68+
**Example:**
69+
```bash
70+
./run_benchmarks.main.kts macos benchmarks=LazyList runs=3 version=1.10.0
71+
```
72+
73+
**Output:**
74+
JSON results are archived to: `benchmarks/build/benchmarks/archive/${platform}/${version}_run${runIndex}`
75+
76+
### `compare_benchmarks.main.kts`
77+
78+
Used to compare benchmark results between two different versions of Compose Multiplatform.
79+
80+
**Usage:**
81+
```bash
82+
./compare_benchmarks.main.kts v1=<version1> v2=<version2> [runs=3] [platform=macos|desktop|web|ios] [benchmarks=<name>] [skipExisting=true] [separateProcess=true]
83+
```
84+
85+
**Example:**
86+
```bash
87+
./compare_benchmarks.main.kts v1=1.9.0 v2=1.10.0 runs=3 platform=macos skipExisting=true
88+
```
89+
90+
### `find_degradation.main.kts`
91+
92+
Performs a binary search over a list of versions to find the first version where a performance degradation (defined as >5% increase in time) was introduced.
93+
94+
**Usage:**
95+
```bash
96+
./find_degradation.main.kts benchmarks=<benchmarkName> versions=<versionsFile> [platform=macos|desktop|web] [skipExisting=true]
97+
```
98+
99+
The `versionsFile` should be a plain text file with one version per line, sorted from oldest to newest.
100+
46101
## Run Desktop
47102
- `./gradlew :benchmarks:run`
48103

@@ -63,9 +118,9 @@ Alternatively you may open `iosApp/iosApp` project in XCode and run the app from
63118
To run specific benchmarks:
64119
- `./run_ios_benchmarks.main.kts <DEVICE ID> benchmarks=AnimatedVisibility,LazyGrid`
65120

66-
To run all benchmarks in a single process (faster but may be less reliable as some
121+
To run each benchmark in a separate process (slower but more reliable as some
67122
benchmarks may affect others within one process):
68-
- `./run_ios_benchmarks.main.kts <DEVICE ID> separateProcess=false`
123+
- `./run_ios_benchmarks.main.kts <DEVICE ID> separateProcess=true`
69124

70125
4. Results are saved in `benchmarks/build/benchmarks/text-reports/` (when using `.main.kts`) or `benchmarks_result/` (when using `.sh`).
71126

benchmarks/multiplatform/benchmarks/src/webMain/kotlin/Main.web.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fun mainBrowser() = MainScope().launch {
3535

3636
runBenchmarks()
3737
println("Completed!")
38-
if (Config.saveStats()) {
38+
if (BenchmarksSaveServerClient.isServerAlive()) {
3939
GlobalScope.launch {
4040
BenchmarksSaveServerClient.stopServer()
4141
}

0 commit comments

Comments
 (0)