-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lists of ints serialization benchmarks (#270)
* Add list wrappers related benchmarks * add list related results dump
- Loading branch information
1 parent
8b4d2e0
commit 8b78af0
Showing
8 changed files
with
264 additions
and
0 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
30 changes: 30 additions & 0 deletions
30
benchmark/src/main/kotlin/com/github/avrokotlin/benchmark/internal/ListWrapperDataClass.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,30 @@ | ||
package com.github.avrokotlin.benchmark.internal | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal data class ListWrapperDataClass(val index: Int, val entries: List<StatsEntry>) { | ||
companion object { | ||
fun create(size: Int, entriesSize: Int, random: RandomUtils = RandomUtils()) = | ||
ListWrapperDataClass(random.nextInt(), List(size) { StatsEntry.create(entriesSize) }) | ||
} | ||
} | ||
|
||
@Serializable | ||
internal data class StatsEntry(val elementId: Long, val values: List<Long>) { | ||
companion object { | ||
fun create(entriesSize: Int, random: RandomUtils = RandomUtils()) = | ||
StatsEntry(random.nextLong(), List(entriesSize) { random.nextLong() }) | ||
} | ||
} | ||
|
||
@Serializable | ||
internal data class ListWrapperDatasClass( | ||
val data: List<ListWrapperDataClass> | ||
) { | ||
companion object { | ||
fun create(size: Int, wrapperSize: Int, entriesSize: Int = 100) = | ||
ListWrapperDatasClass(data = List(size) { ListWrapperDataClass.create(wrapperSize, entriesSize) } | ||
) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../src/main/kotlin/com/github/avrokotlin/benchmark/lists/ApacheAvroReflectListsBenchmark.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,43 @@ | ||
package com.github.avrokotlin.benchmark.lists | ||
|
||
import com.github.avrokotlin.avro4k.Avro | ||
import com.github.avrokotlin.avro4k.encodeToByteArray | ||
import com.github.avrokotlin.benchmark.internal.ListWrapperDatasClass | ||
import kotlinx.benchmark.Benchmark | ||
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.OutputStream | ||
|
||
internal class ApacheAvroReflectListsBenchmark : SerializationListsBenchmark() { | ||
lateinit var writer: DatumWriter<ListWrapperDatasClass> | ||
lateinit var encoder: Encoder | ||
lateinit var reader: DatumReader<ListWrapperDatasClass> | ||
|
||
lateinit var data: ByteArray | ||
|
||
override fun setup() { | ||
writer = ReflectData.get().createDatumWriter(schema) as DatumWriter<ListWrapperDatasClass> | ||
encoder = EncoderFactory.get().directBinaryEncoder(OutputStream.nullOutputStream(), null) | ||
|
||
reader = ReflectData.get().createDatumReader(schema) as DatumReader<ListWrapperDatasClass> | ||
} | ||
|
||
override fun prepareBinaryData() { | ||
data = Avro.encodeToByteArray(schema, lists) | ||
} | ||
|
||
@Benchmark | ||
fun read() { | ||
val decoder = DecoderFactory.get().binaryDecoder(data, null) | ||
reader.read(null, decoder) | ||
} | ||
|
||
@Benchmark | ||
fun write() { | ||
writer.write(lists, encoder) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...kotlin/com/github/avrokotlin/benchmark/lists/Avro4kGenericWithApacheAvroListsBenchmark.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,50 @@ | ||
package com.github.avrokotlin.benchmark.lists | ||
|
||
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.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.OutputStream | ||
|
||
internal class Avro4kGenericWithApacheAvroListsBenchmark : SerializationListsBenchmark() { | ||
lateinit var writer: DatumWriter<Any?> | ||
lateinit var encoder: Encoder | ||
lateinit var reader: DatumReader<Any?> | ||
|
||
lateinit var data: ByteArray | ||
|
||
override fun setup() { | ||
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, lists) | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Benchmark | ||
fun read() { | ||
val decoder = DecoderFactory.get().binaryDecoder(data, null) | ||
val genericData = reader.read(null, decoder) | ||
Avro.decodeFromGenericData<Clients>(schema, genericData) | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Benchmark | ||
fun write() { | ||
val genericData = Avro.encodeToGenericData(schema, lists) | ||
writer.write(genericData, encoder) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
benchmark/src/main/kotlin/com/github/avrokotlin/benchmark/lists/Avro4kListsBenchmark.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 @@ | ||
package com.github.avrokotlin.benchmark.lists | ||
|
||
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.ListWrapperDatasClass | ||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import java.io.OutputStream | ||
|
||
internal class Avro4kListsBenchmark : SerializationListsBenchmark() { | ||
lateinit var data: ByteArray | ||
|
||
override fun setup() { | ||
} | ||
|
||
override fun prepareBinaryData() { | ||
data = Avro.encodeToByteArray(schema, lists) | ||
} | ||
|
||
@Benchmark | ||
fun read() { | ||
Avro.decodeFromByteArray<ListWrapperDatasClass>(schema, data) | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Benchmark | ||
fun write() { | ||
Avro.encodeToStream(schema, lists, OutputStream.nullOutputStream()) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
benchmark/src/main/kotlin/com/github/avrokotlin/benchmark/lists/JacksonAvroListsBenchmark.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.lists | ||
|
||
import com.fasterxml.jackson.databind.MapperFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.ObjectReader | ||
import com.fasterxml.jackson.databind.ObjectWriter | ||
import com.fasterxml.jackson.dataformat.avro.AvroMapper | ||
import com.fasterxml.jackson.dataformat.avro.AvroSchema | ||
import com.fasterxml.jackson.dataformat.avro.jsr310.AvroJavaTimeModule | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import com.github.avrokotlin.avro4k.Avro | ||
import com.github.avrokotlin.avro4k.encodeToByteArray | ||
import com.github.avrokotlin.benchmark.internal.ListWrapperDatasClass | ||
import kotlinx.benchmark.Benchmark | ||
import java.io.OutputStream | ||
|
||
|
||
internal class JacksonAvroListsBenchmark : SerializationListsBenchmark() { | ||
lateinit var writer: ObjectWriter | ||
lateinit var reader: ObjectReader | ||
|
||
lateinit var data: ByteArray | ||
|
||
override fun setup() { | ||
writer = ListWrapperDatasClass::class.java.createWriter() | ||
reader = ListWrapperDatasClass::class.java.createReader() | ||
} | ||
|
||
override fun prepareBinaryData() { | ||
data = Avro.encodeToByteArray(schema, lists) | ||
} | ||
|
||
@Benchmark | ||
fun read() { | ||
reader.readValue<ListWrapperDatasClass>(data) | ||
} | ||
|
||
@Benchmark | ||
fun write() { | ||
writer.writeValue(OutputStream.nullOutputStream(), lists) | ||
} | ||
|
||
private fun <T> Class<T>.createWriter(): ObjectWriter { | ||
val mapper = avroMapper() | ||
|
||
return mapper.writer(AvroSchema(schema)).forType(this) | ||
} | ||
|
||
private fun <T> Class<T>.createReader(): ObjectReader { | ||
val mapper = avroMapper() | ||
|
||
return mapper.reader(AvroSchema(schema)).forType(this) | ||
} | ||
|
||
private fun avroMapper(): ObjectMapper = AvroMapper() | ||
.disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY) | ||
.registerKotlinModule() | ||
.registerModule(AvroJavaTimeModule()) | ||
} |
31 changes: 31 additions & 0 deletions
31
...mark/src/main/kotlin/com/github/avrokotlin/benchmark/lists/SerializationListsBenchmark.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,31 @@ | ||
package com.github.avrokotlin.benchmark.lists | ||
|
||
import com.github.avrokotlin.avro4k.Avro | ||
import com.github.avrokotlin.avro4k.schema | ||
import com.github.avrokotlin.benchmark.internal.Clients | ||
import com.github.avrokotlin.benchmark.internal.ClientsGenerator | ||
import com.github.avrokotlin.benchmark.internal.ListWrapperDataClass | ||
import com.github.avrokotlin.benchmark.internal.ListWrapperDatasClass | ||
import kotlinx.benchmark.* | ||
import java.util.concurrent.TimeUnit | ||
|
||
|
||
@State(Scope.Benchmark) | ||
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
@BenchmarkMode(Mode.Throughput) | ||
@Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS) | ||
internal abstract class SerializationListsBenchmark { | ||
lateinit var lists: ListWrapperDatasClass | ||
val schema = Avro.schema<ListWrapperDatasClass>() | ||
|
||
@Setup | ||
fun initTestData() { | ||
setup() | ||
lists = ListWrapperDatasClass.create(10, 10000) | ||
prepareBinaryData() | ||
} | ||
|
||
abstract fun setup() | ||
|
||
abstract fun prepareBinaryData() | ||
} |