Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmarking #103

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,9 @@ gradle-app.setting

# Cache of project
.gradletasknamecache

.classpath
.project
.settings
.kotlin
kotlin-js-store/
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("multiplatform") version Dependencies.Versions.kotlin apply false
kotlin("plugin.serialization") version Dependencies.Versions.kotlin apply false
id("org.jetbrains.kotlinx.benchmark") version Dependencies.Versions.benchmark apply false
}

repositories {
Expand Down
7 changes: 4 additions & 3 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
object Dependencies {
object Versions {
const val kotlin = "2.0.20"
const val kotlin = "2.1.0"
const val serialization = "1.7.3"
const val datetime = "0.6.1"
const val ktlintGradle = "12.1.1"
const val dokkaGradle = "1.9.20"
const val ktlintGradle = "12.1.2"
const val dokkaGradle = "2.0.0"
const val benchmark = "0.4.13"
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 19 additions & 3 deletions serialization-msgpack-timestamp-extension/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ plugins {
id("maven-publish")
id("signing")
id("org.jetbrains.dokka")
id("org.jetbrains.kotlinx.benchmark")
}

kotlin {
jvm()
applyDefaultHierarchyTemplate()
jvm {
compilations.create("benchmark") {
associateWith([email protected]("main"))
}
}
js {
browser {
testTask {
Expand All @@ -17,10 +23,9 @@ kotlin {
}
}
}
applyDefaultHierarchyTemplate()
jvm()
iosX64()
iosArm64()
iosX64()
iosSimulatorArm64()
tvosX64()
tvosArm64()
Expand Down Expand Up @@ -61,10 +66,21 @@ kotlin {
implementation(kotlin("test-junit"))
}
}
val jvmBenchmark by getting {
dependencies {
implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark))
}
}
jsTest {
dependencies {
implementation(kotlin("test-js"))
}
}
}
}

benchmark {
targets {
register("jvmBenchmark")
}
}
21 changes: 18 additions & 3 deletions serialization-msgpack-unsigned-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ plugins {
id("maven-publish")
id("signing")
id("org.jetbrains.dokka")
id("org.jetbrains.kotlinx.benchmark")
}

kotlin {
jvm()
jvm {
compilations.create("benchmark") {
associateWith([email protected]("main"))
}
}
js {
browser {
testTask {
Expand All @@ -18,9 +23,8 @@ kotlin {
}
}
applyDefaultHierarchyTemplate()
jvm()
iosX64()
iosArm64()
iosX64()
iosSimulatorArm64()
tvosX64()
tvosArm64()
Expand Down Expand Up @@ -60,10 +64,21 @@ kotlin {
implementation(kotlin("test-junit"))
}
}
val jvmBenchmark by getting {
dependencies {
implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark))
}
}
jsTest {
dependencies {
implementation(kotlin("test-js"))
}
}
}
}

benchmark {
targets {
register("jvmBenchmark")
}
}
20 changes: 18 additions & 2 deletions serialization-msgpack/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ plugins {
id("maven-publish")
id("signing")
id("org.jetbrains.dokka")
id("org.jetbrains.kotlinx.benchmark")
}

kotlin {
jvm {
compilations.create("benchmark") {
associateWith([email protected]("main"))
}
}
js {
browser {
testTask {
Expand All @@ -17,9 +23,8 @@ kotlin {
}
}
applyDefaultHierarchyTemplate()
jvm()
iosX64()
iosArm64()
iosX64()
iosSimulatorArm64()
tvosX64()
tvosArm64()
Expand Down Expand Up @@ -59,10 +64,21 @@ kotlin {
implementation(kotlin("test-junit"))
}
}
val jvmBenchmark by getting {
dependencies {
implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark))
}
}
jsTest {
dependencies {
implementation(kotlin("test-js"))
}
}
}
}

benchmark {
targets {
register("jvmBenchmark")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,41 @@ object TestData {
"a474657374" to "test",
"a82d31323377686174" to "-123what",
"a82d31323377686174" to "-123what",
"bf74657374747474747474747474747474747474747474747474747474747474" to "testttttttttttttttttttttttttttt", // Max fixStr size
"aac48dc487c48dc487c2bc" to "čćčć¼", // UTF-8 support
// Max fixStr size
"bf74657374747474747474747474747474747474747474747474747474747474" to "testttttttttttttttttttttttttttt",
// UTF-8 support
"aac48dc487c48dc487c2bc" to "čćčć¼",
)
val str8TestPairs =
arrayOf(
"d9207465737474747474747474747474747474747474747474747474747474747474" to "testtttttttttttttttttttttttttttt", // Min Str8 size
"d92a7465737474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc" to "testttttttttttttttttttttttttttttčćčć¼", // UTF-8 support
"d9ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to "testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", // Max Str8 size
// Min Str8 size
"d9207465737474747474747474747474747474747474747474747474747474747474" to "testtttttttttttttttttttttttttttt",
// UTF-8 support
"d92a7465737474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc" to
"testttttttttttttttttttttttttttttčćčć¼",
// Max Str8 size
@Suppress("ktlint:standard:max-line-length")
"d9ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474"
to
"testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
)
val str16TestPairs =
arrayOf(
"da010074657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to "testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", // Min Str16 size
"da010a74657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc" to "testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttčćčć¼", // UTF-8 support
// Min Str16 size
@Suppress("ktlint:standard:max-line-length")
"da010074657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474"
to "testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
// UTF-8 support
@Suppress("ktlint:standard:max-line-length")
"da010a74657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc"
to "testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttčćčć¼",
)
val bin8TestPairs =
arrayOf(
"c409010203040506070809" to byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9),
"c400" to byteArrayOf(),
"c4ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to byteArrayOf(116, 101, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116),
"c4ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to byteArrayOf(116, 101, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116
),
)
val intArrayTestPairs =
arrayOf(
Expand All @@ -118,7 +134,8 @@ object TestData {
val stringArrayTestPairs =
arrayOf(
"92a3616263a3646566" to arrayOf("abc", "def"),
"92d921616266647366736466736466647366736466736673646673647364666466646663a3616473" to arrayOf("abfdsfsdfsdfdsfsdfsfsdfsdsdfdfdfc", "ads"),
"92d921616266647366736466736466647366736466736673646673647364666466646663a3616473" to
arrayOf("abfdsfsdfsdfdsfsdfsfsdfsdsdfdfdfc", "ads"),
)
val mixedListTestPairs =
arrayOf(
Expand Down Expand Up @@ -203,7 +220,10 @@ object TestData {
)
val unknownKeysTestPairs =
arrayOf(
"85aa74657374537472696e67a3646566ab7465737449676e6f72656491a969676e6f7265206d65a774657374496e747bab74657374556e6b6e6f776ea7756e6b6e6f776eab74657374426f6f6c65616ec3" to SampleClass("def", 123, true),
@Suppress("ktlint:standard:max-line-length")
"85aa74657374537472696e67a3646566ab7465737449676e6f72656491a969676e6f7265206d65a774657374496e747bab74657374556e6b6e6f776ea7756e6b6e6f776eab74657374426f6f6c65616ec3"
to
SampleClass("def", 123, true),
)

val floatEncodedDataTestPairs =
Expand All @@ -221,8 +241,14 @@ object TestData {
)
val nestedSampleClassWithMissingValue =
arrayOf(
"84aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656482aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3" to SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null)),
"85aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656483aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3ae616e6f74686572556e6b6e6f776ea474657374ac7365636f6e644e657374656481ab74657374426f6f6c65616ec2" to SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null), SampleClassWithNestedClass.NestedClass(null)),
@Suppress("ktlint:standard:max-line-length")
"84aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656482aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3"
to
SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null)),
@Suppress("ktlint:standard:max-line-length")
"85aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656483aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3ae616e6f74686572556e6b6e6f776ea474657374ac7365636f6e644e657374656481ab74657374426f6f6c65616ec2"
to
SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null), SampleClassWithNestedClass.NestedClass(null)),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.ensarsarajcic.kotlinx.serialization.msgpack

import com.ensarsarajcic.kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder
import com.ensarsarajcic.kotlinx.serialization.msgpack.stream.toMsgPackBuffer
import kotlinx.benchmark.Benchmark
import kotlinx.benchmark.BenchmarkMode
import kotlinx.benchmark.BenchmarkTimeUnit
import kotlinx.benchmark.Measurement
import kotlinx.benchmark.Mode
import kotlinx.benchmark.OutputTimeUnit
import kotlinx.benchmark.Scope
import kotlinx.benchmark.State
import kotlinx.serialization.Serializable
import kotlinx.serialization.modules.SerializersModule

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS)
@Measurement(iterations = 20, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS)
@State(Scope.Benchmark)
open class DeserializeBenchmarks {
@Serializable
data class SampleClassWithNestedClass(
val testString: String,
val testInt: Int,
val testBoolean: Boolean,
val testNested: NestedClass,
val secondNested: NestedClass? = null,
) {
@Serializable
data class NestedClass(
val testInt: Int? = null,
)
}

// The actual benchmark method
@Benchmark
fun benchmarkMethod() {
val decoder =
BasicMsgPackDecoder(
MsgPackConfiguration.default.copy(ignoreUnknownKeys = true),
SerializersModule {
},
@Suppress("ktlint:standard:max-line-length")
"85aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656483aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3ae616e6f74686572556e6b6e6f776ea474657374ac7365636f6e644e657374656481ab74657374426f6f6c65616ec2".hexStringToByteArray().toMsgPackBuffer(),
)
SampleClassWithNestedClass.serializer().deserialize(decoder)
}
}

fun String.hexStringToByteArray() = ByteArray(this.length / 2) { this.substring(it * 2, it * 2 + 2).toInt(16).toByte() }
Loading
Loading