Skip to content

Commit 4513ac4

Browse files
authored
Add benchmarks suite (#129)
Added kotlinx-io benchmarks suite. The suite aimed to track how the performance of the library changes between releases and also to validate the performance on platforms other than JVM. Currently, only benchmarks covering the very core part of an API were added as that API's part likely won't change in the near future. The suite doesn't facilitate comparing the performance with other libraries (Okio, ktor-io), but for Okio it could be done by simply replacing import statements in benchmarks fromkotlinx.io to okio, thanks to API's compatibility.
1 parent 880c6e6 commit 4513ac4

File tree

10 files changed

+528
-0
lines changed

10 files changed

+528
-0
lines changed

benchmarks/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# kotlinx-io benchmarks
2+
3+
The module consists of benchmarks aimed to track performance of kotlinx-io implementation.
4+
5+
Currently, the suite includes benchmarks on:
6+
- the core Buffer API usage: read/write primitive types, arrays, UTF8 strings;
7+
- basic `peek` usage;
8+
- segment pooling performance.
9+
10+
The suite doesn't include benchmarks for more complex APIs inherited from Okio as these APIs are subject to change.
11+
Such benchmarks will be added later along with corresponding changes in the library.

benchmarks/build.gradle.kts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
import kotlinx.benchmark.gradle.JvmBenchmarkTarget
7+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
8+
import org.jetbrains.kotlin.konan.target.HostManager
9+
import org.jetbrains.kotlin.konan.target.KonanTarget
10+
11+
plugins {
12+
kotlin("multiplatform")
13+
id("org.jetbrains.kotlinx.benchmark") version "0.4.8"
14+
}
15+
16+
kotlin {
17+
jvm()
18+
// TODO: consider supporting non-host native targets.
19+
if (HostManager.host === KonanTarget.MACOS_X64) macosX64("native")
20+
if (HostManager.host === KonanTarget.MACOS_ARM64) macosArm64("native")
21+
if (HostManager.hostIsLinux) linuxX64("native")
22+
if (HostManager.hostIsMingw) mingwX64("native")
23+
24+
sourceSets {
25+
commonMain {
26+
dependencies {
27+
implementation(project(":kotlinx-io-core"))
28+
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.8")
29+
}
30+
}
31+
32+
val jvmMain by getting {
33+
dependsOn(commonMain.get())
34+
}
35+
36+
val nativeMain by getting {
37+
dependsOn(commonMain.get())
38+
}
39+
}
40+
}
41+
42+
benchmark {
43+
targets {
44+
register("jvm") {
45+
this as JvmBenchmarkTarget
46+
jmhVersion = "1.36"
47+
}
48+
register("native")
49+
}
50+
}

0 commit comments

Comments
 (0)