diff options
Diffstat (limited to 'benchmark/src/jmh/kotlin/kotlinx/benchmarks/protobuf/ProtoListLikeBenchmark.kt')
-rw-r--r-- | benchmark/src/jmh/kotlin/kotlinx/benchmarks/protobuf/ProtoListLikeBenchmark.kt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/benchmark/src/jmh/kotlin/kotlinx/benchmarks/protobuf/ProtoListLikeBenchmark.kt b/benchmark/src/jmh/kotlin/kotlinx/benchmarks/protobuf/ProtoListLikeBenchmark.kt new file mode 100644 index 00000000..af1699dd --- /dev/null +++ b/benchmark/src/jmh/kotlin/kotlinx/benchmarks/protobuf/ProtoListLikeBenchmark.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ +package kotlinx.benchmarks.protobuf + +import kotlinx.serialization.* +import kotlinx.serialization.protobuf.* +import org.openjdk.jmh.annotations.* +import java.util.concurrent.* + +@Warmup(iterations = 5, time = 1) +@Measurement(iterations = 5, time = 1) +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) +@Fork(1) +open class ProtoListLikeBenchmark { + + @Serializable + class Holder(val a: Int, val b: Int, val c: Long, val d: Double) + + @Serializable + class HolderList(val h1: Holder, val h2: Holder, val h3: Holder, val h4: Holder, val h5: Holder) + + private val h = Holder(1, 2, 3L, 4.0) + private val value = HolderList(h, h, h, h, h) + private val bytes = ProtoBuf.encodeToByteArray(value) + + @Benchmark + fun toBytes() = ProtoBuf.encodeToByteArray(HolderList.serializer(), value) + + @Benchmark + fun fromBytes() = ProtoBuf.decodeFromByteArray(HolderList.serializer(), bytes) +} |