diff --git a/.gitignore b/.gitignore index 256f2f8..3e49fef 100644 --- a/.gitignore +++ b/.gitignore @@ -110,5 +110,9 @@ gradle-app.setting # Cache of project .gradletasknamecache + +.classpath +.project +.settings .kotlin kotlin-js-store/ diff --git a/build.gradle.kts b/build.gradle.kts index 8be6e3e..baf2766 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index b3c8cdb..822876a 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -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" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d642e7f..81aa1c0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/serialization-msgpack-timestamp-extension/build.gradle.kts b/serialization-msgpack-timestamp-extension/build.gradle.kts index f520b0f..5f6bb76 100644 --- a/serialization-msgpack-timestamp-extension/build.gradle.kts +++ b/serialization-msgpack-timestamp-extension/build.gradle.kts @@ -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(this@jvm.compilations.getByName("main")) + } + } js { browser { testTask { @@ -17,10 +23,9 @@ kotlin { } } } - applyDefaultHierarchyTemplate() - jvm() iosX64() iosArm64() + iosX64() iosSimulatorArm64() tvosX64() tvosArm64() @@ -61,6 +66,11 @@ kotlin { implementation(kotlin("test-junit")) } } + val jvmBenchmark by getting { + dependencies { + implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) + } + } jsTest { dependencies { implementation(kotlin("test-js")) @@ -68,3 +78,9 @@ kotlin { } } } + +benchmark { + targets { + register("jvmBenchmark") + } +} diff --git a/serialization-msgpack-unsigned-support/build.gradle.kts b/serialization-msgpack-unsigned-support/build.gradle.kts index 1302789..22aafee 100644 --- a/serialization-msgpack-unsigned-support/build.gradle.kts +++ b/serialization-msgpack-unsigned-support/build.gradle.kts @@ -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(this@jvm.compilations.getByName("main")) + } + } js { browser { testTask { @@ -18,9 +23,8 @@ kotlin { } } applyDefaultHierarchyTemplate() - jvm() - iosX64() iosArm64() + iosX64() iosSimulatorArm64() tvosX64() tvosArm64() @@ -60,6 +64,11 @@ kotlin { implementation(kotlin("test-junit")) } } + val jvmBenchmark by getting { + dependencies { + implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) + } + } jsTest { dependencies { implementation(kotlin("test-js")) @@ -67,3 +76,9 @@ kotlin { } } } + +benchmark { + targets { + register("jvmBenchmark") + } +} diff --git a/serialization-msgpack/build.gradle.kts b/serialization-msgpack/build.gradle.kts index 07796b7..a968680 100644 --- a/serialization-msgpack/build.gradle.kts +++ b/serialization-msgpack/build.gradle.kts @@ -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(this@jvm.compilations.getByName("main")) + } + } js { browser { testTask { @@ -17,9 +23,8 @@ kotlin { } } applyDefaultHierarchyTemplate() - jvm() - iosX64() iosArm64() + iosX64() iosSimulatorArm64() tvosX64() tvosArm64() @@ -59,6 +64,11 @@ kotlin { implementation(kotlin("test-junit")) } } + val jvmBenchmark by getting { + dependencies { + implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) + } + } jsTest { dependencies { implementation(kotlin("test-js")) @@ -66,3 +76,9 @@ kotlin { } } } + +benchmark { + targets { + register("jvmBenchmark") + } +} diff --git a/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt b/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt index 3ca9d51..11bd661 100644 --- a/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt +++ b/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt @@ -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( @@ -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( @@ -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 = @@ -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)), ) } diff --git a/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/DeserializeBenchmarks.kt b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/DeserializeBenchmarks.kt new file mode 100644 index 0000000..1ff5aac --- /dev/null +++ b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/DeserializeBenchmarks.kt @@ -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() } diff --git a/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/SerializeBenchmarks.kt b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/SerializeBenchmarks.kt new file mode 100644 index 0000000..addd13e --- /dev/null +++ b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/SerializeBenchmarks.kt @@ -0,0 +1,71 @@ +package com.ensarsarajcic.kotlinx.serialization.msgpack + +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.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToByteArray + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) +@Measurement(iterations = 20, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) +@State(Scope.Benchmark) +open class SerializeBenchmarks { + @Serializable + data class SampleClass( + @SerialName("testString") + val testString: String, + val testInt: Int, + val testBoolean: Boolean, + ) + + @Serializable + data class SampleClassWithNestedClass( + val testString: String, + val testInt: Int, + val testBoolean: Boolean, + val testNested: NestedClass, + val testSample: SampleClass, + val testSampleList: List, + val testSampleMap: Map, + val extraBytes: ByteArray, + val secondNested: NestedClass? = null, + ) { + @Serializable + data class NestedClass( + val testInt: Int? = null, + ) + } + + // The actual benchmark method + @Benchmark + fun benchmarkMethod() { + val instance = + SampleClassWithNestedClass( + testString = "testString", + testInt = 10, + testBoolean = true, + testNested = SampleClassWithNestedClass.NestedClass(5), + testSample = SampleClass(testString = "testString2", testInt = 17, testBoolean = false), + testSampleList = + listOf( + SampleClass("testString3", testInt = 25, testBoolean = true), + SampleClass("testString4", testInt = 100, testBoolean = false), + ), + testSampleMap = + mapOf( + "testString5" to SampleClass("testString5", testInt = 12, testBoolean = false), + "testString6" to SampleClass("testString6", testInt = 15, testBoolean = true), + ), + extraBytes = byteArrayOf(0x12, 0x13, 0x14, 0x15), + secondNested = SampleClassWithNestedClass.NestedClass(null), + ) + MsgPack.encodeToByteArray(instance) + } +}