-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added map-related protobuf benchmark * Reimplemented ProtoWireType lookup
- Loading branch information
Showing
3 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
benchmark/src/jmh/kotlin/kotlinx/benchmarks/protobuf/ProtoMapBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.benchmarks.protobuf | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToByteArray | ||
import kotlinx.serialization.protobuf.ProtoBuf | ||
import org.openjdk.jmh.annotations.* | ||
import java.util.concurrent.TimeUnit | ||
|
||
@Warmup(iterations = 5, time = 1) | ||
@Measurement(iterations = 5, time = 1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
@Fork(1) | ||
open class ProtoMapBenchmark { | ||
|
||
@Serializable | ||
class Holder(val map: Map<String, Int>) | ||
|
||
private val value = Holder((0..128).associateBy { it.toString() }) | ||
private val bytes = ProtoBuf.encodeToByteArray(value) | ||
|
||
@Benchmark | ||
fun toBytes() = ProtoBuf.encodeToByteArray(Holder.serializer(), value) | ||
|
||
@Benchmark | ||
fun fromBytes() = ProtoBuf.decodeFromByteArray(Holder.serializer(), bytes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters