-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from Chuckame/improve-benchmark
Improve benchmark
- Loading branch information
Showing
33 changed files
with
1,128 additions
and
477 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
public abstract interface class com/github/avrokotlin/benchmark/Partner { | ||
public static final field Companion Lcom/github/avrokotlin/benchmark/Partner$Companion; | ||
public final class com/github/avrokotlin/benchmark/internal/CharJacksonDeserializer : com/fasterxml/jackson/databind/deser/std/StdDeserializer { | ||
public fun <init> ()V | ||
public fun deserialize (Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Character; | ||
public synthetic fun deserialize (Lcom/fasterxml/jackson/core/JsonParser;Lcom/fasterxml/jackson/databind/DeserializationContext;)Ljava/lang/Object; | ||
} | ||
|
||
public final class com/github/avrokotlin/benchmark/Partner$Companion { | ||
public final class com/github/avrokotlin/benchmark/internal/CharJacksonSerializer : com/fasterxml/jackson/databind/ser/std/StdSerializer { | ||
public fun <init> ()V | ||
public fun acceptJsonFormatVisitor (Lcom/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorWrapper;Lcom/fasterxml/jackson/databind/JavaType;)V | ||
public fun serialize (Ljava/lang/Character;Lcom/fasterxml/jackson/core/JsonGenerator;Lcom/fasterxml/jackson/databind/SerializerProvider;)V | ||
public synthetic fun serialize (Ljava/lang/Object;Lcom/fasterxml/jackson/core/JsonGenerator;Lcom/fasterxml/jackson/databind/SerializerProvider;)V | ||
} | ||
|
||
public abstract interface class com/github/avrokotlin/benchmark/internal/Partner { | ||
public static final field Companion Lcom/github/avrokotlin/benchmark/internal/Partner$Companion; | ||
} | ||
|
||
public final class com/github/avrokotlin/benchmark/internal/Partner$Companion { | ||
public final fun serializer ()Lkotlinx/serialization/KSerializer; | ||
} | ||
|
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
54 changes: 54 additions & 0 deletions
54
benchmark/src/main/kotlin/com/github/avrokotlin/benchmark/ApacheAvroReflectBenchmark.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,54 @@ | ||
package com.github.avrokotlin.benchmark | ||
|
||
import com.github.avrokotlin.avro4k.Avro | ||
import com.github.avrokotlin.avro4k.encodeToByteArray | ||
import com.github.avrokotlin.benchmark.internal.Clients | ||
import kotlinx.benchmark.Benchmark | ||
import org.apache.avro.Conversions | ||
import org.apache.avro.data.TimeConversions | ||
import org.apache.avro.io.DatumReader | ||
import org.apache.avro.io.DatumWriter | ||
import org.apache.avro.io.DecoderFactory | ||
import org.apache.avro.io.Encoder | ||
import org.apache.avro.io.EncoderFactory | ||
import org.apache.avro.reflect.ReflectData | ||
import java.io.ByteArrayInputStream | ||
import java.io.OutputStream | ||
|
||
internal class ApacheAvroReflectBenchmark : SerializationBenchmark() { | ||
lateinit var writer: DatumWriter<Clients> | ||
lateinit var encoder: Encoder | ||
lateinit var reader: DatumReader<Clients> | ||
|
||
lateinit var data: ByteArray | ||
var writeMode = false | ||
|
||
override fun setup() { | ||
ReflectData.get().addLogicalTypeConversion(Conversions.UUIDConversion()) | ||
ReflectData.get().addLogicalTypeConversion(Conversions.DecimalConversion()) | ||
ReflectData.get().addLogicalTypeConversion(TimeConversions.DateConversion()) | ||
ReflectData.get().addLogicalTypeConversion(TimeConversions.TimestampMillisConversion()) | ||
|
||
writer = ReflectData.get().createDatumWriter(schema) as DatumWriter<Clients> | ||
encoder = EncoderFactory.get().directBinaryEncoder(OutputStream.nullOutputStream(), null) | ||
|
||
reader = ReflectData.get().createDatumReader(schema) as DatumReader<Clients> | ||
} | ||
|
||
override fun prepareBinaryData() { | ||
data = Avro.encodeToByteArray(schema, clients) | ||
} | ||
|
||
@Benchmark | ||
fun read() { | ||
if (writeMode) writeMode = false | ||
val decoder = DecoderFactory.get().directBinaryDecoder(ByteArrayInputStream(data), null) | ||
reader.read(null, decoder) | ||
} | ||
|
||
@Benchmark | ||
fun write() { | ||
if (!writeMode) writeMode = true | ||
writer.write(clients, encoder) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
benchmark/src/main/kotlin/com/github/avrokotlin/benchmark/Avro4kBenchmark.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,35 @@ | ||
package com.github.avrokotlin.benchmark | ||
|
||
import com.github.avrokotlin.avro4k.Avro | ||
import com.github.avrokotlin.avro4k.decodeFromByteArray | ||
import com.github.avrokotlin.avro4k.encodeToByteArray | ||
import com.github.avrokotlin.avro4k.encodeToStream | ||
import com.github.avrokotlin.benchmark.internal.Clients | ||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import java.io.OutputStream | ||
|
||
internal class Avro4kBenchmark : SerializationBenchmark() { | ||
lateinit var data: ByteArray | ||
var writeMode = false | ||
|
||
override fun setup() { | ||
} | ||
|
||
override fun prepareBinaryData() { | ||
data = Avro.encodeToByteArray(schema, clients) | ||
} | ||
|
||
@Benchmark | ||
fun read() { | ||
if (writeMode) writeMode = false | ||
Avro.decodeFromByteArray<Clients>(schema, data) | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Benchmark | ||
fun write() { | ||
if (!writeMode) writeMode = true | ||
Avro.encodeToStream(schema, clients, OutputStream.nullOutputStream()) | ||
} | ||
} |
53 changes: 0 additions & 53 deletions
53
benchmark/src/main/kotlin/com/github/avrokotlin/benchmark/Avro4kClientsBenchmark.kt
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
...k/src/main/kotlin/com/github/avrokotlin/benchmark/Avro4kGenericWithApacheAvroBenchmark.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,59 @@ | ||
package com.github.avrokotlin.benchmark | ||
|
||
import com.github.avrokotlin.avro4k.Avro | ||
import com.github.avrokotlin.avro4k.decodeFromGenericData | ||
import com.github.avrokotlin.avro4k.encodeToByteArray | ||
import com.github.avrokotlin.avro4k.encodeToGenericData | ||
import com.github.avrokotlin.benchmark.internal.Clients | ||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import org.apache.avro.Conversions | ||
import org.apache.avro.generic.GenericData | ||
import org.apache.avro.io.DatumReader | ||
import org.apache.avro.io.DatumWriter | ||
import org.apache.avro.io.DecoderFactory | ||
import org.apache.avro.io.Encoder | ||
import org.apache.avro.io.EncoderFactory | ||
import java.io.ByteArrayInputStream | ||
import java.io.OutputStream | ||
|
||
internal class Avro4kGenericWithApacheAvroBenchmark : SerializationBenchmark() { | ||
lateinit var writer: DatumWriter<Any?> | ||
lateinit var encoder: Encoder | ||
lateinit var reader: DatumReader<Any?> | ||
|
||
lateinit var data: ByteArray | ||
var writeMode = false | ||
|
||
override fun setup() { | ||
GenericData.get().addLogicalTypeConversion(Conversions.DecimalConversion()) | ||
// GenericData.get().addLogicalTypeConversion(TimeConversions.DateConversion()) | ||
// GenericData.get().addLogicalTypeConversion(TimeConversions.TimestampMillisConversion()) | ||
|
||
writer = GenericData.get().createDatumWriter(schema) as DatumWriter<Any?> | ||
encoder = EncoderFactory.get().directBinaryEncoder(OutputStream.nullOutputStream(), null) | ||
|
||
reader = GenericData.get().createDatumReader(schema) as DatumReader<Any?> | ||
} | ||
|
||
override fun prepareBinaryData() { | ||
data = Avro.encodeToByteArray(schema, clients) | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Benchmark | ||
fun read() { | ||
if (writeMode) writeMode = false | ||
val decoder = DecoderFactory.get().directBinaryDecoder(ByteArrayInputStream(data), null) | ||
val genericData = reader.read(null, decoder) | ||
Avro { validateSerialization = true }.decodeFromGenericData<Clients>(schema, genericData) | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Benchmark | ||
fun write() { | ||
if (!writeMode) writeMode = true | ||
val genericData = Avro.encodeToGenericData(schema, clients) | ||
writer.write(genericData, encoder) | ||
} | ||
} |
Oops, something went wrong.