-
Notifications
You must be signed in to change notification settings - Fork 5
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 #38 from Peanuuutz/dev
0.3.1 Improve tests, fix several bugs.
- Loading branch information
Showing
60 changed files
with
3,503 additions
and
1,096 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
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,44 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
kotlin("jvm") | ||
kotlin("plugin.serialization") | ||
kotlin("plugin.allopen") | ||
kotlin("kapt") | ||
|
||
id("me.champeau.jmh") | ||
} | ||
|
||
dependencies { | ||
jmh("org.openjdk.jmh:jmh-core:1.36") | ||
kaptJmh("org.openjdk.jmh:jmh-generator-annprocess:1.36") | ||
|
||
// tomlkt | ||
jmh(project(":core")) | ||
// toml4j | ||
jmh("com.moandjiezana.toml:toml4j:0.7.2") | ||
// ktoml | ||
jmh("com.akuleshov7:ktoml-core:0.5.0") | ||
// jackson | ||
jmh("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.15.1") | ||
jmh("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.1") | ||
jmh("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.1") | ||
// ... | ||
|
||
} | ||
|
||
jmh { | ||
includes.set(listOf("test.Benchmark")) | ||
} | ||
|
||
allOpen { | ||
annotation("org.openjdk.jmh.annotations.Measurement") | ||
} | ||
|
||
tasks { | ||
withType<KotlinCompile> { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
} |
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,82 @@ | ||
package test | ||
|
||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import kotlinx.serialization.decodeFromString | ||
import org.openjdk.jmh.annotations.Benchmark | ||
import org.openjdk.jmh.annotations.BenchmarkMode | ||
import org.openjdk.jmh.annotations.Fork | ||
import org.openjdk.jmh.annotations.Measurement | ||
import org.openjdk.jmh.annotations.Mode | ||
import org.openjdk.jmh.annotations.OutputTimeUnit | ||
import org.openjdk.jmh.annotations.Scope | ||
import org.openjdk.jmh.annotations.State | ||
import org.openjdk.jmh.annotations.Threads | ||
import org.openjdk.jmh.annotations.Warmup | ||
import java.util.concurrent.TimeUnit | ||
|
||
@State(Scope.Thread) | ||
object TomlObjects { | ||
val tomlkt = net.peanuuutz.tomlkt.Toml | ||
val toml4j = com.moandjiezana.toml.Toml() | ||
val ktoml = com.akuleshov7.ktoml.Toml | ||
val jackson = com.fasterxml.jackson.dataformat.toml.TomlMapper().apply { | ||
registerKotlinModule() | ||
registerModule(JavaTimeModule()) | ||
} | ||
} | ||
|
||
/* | ||
Benchmark Mode Cnt Score Error Units | ||
Benchmark.jacksonWithType avgt 10 7696.731 ± 112.218 ns/op | ||
Benchmark.jacksonWithClass avgt 10 8090.255 ± 420.727 ns/op | ||
Benchmark.tomlktWithoutSerializer avgt 10 10265.799 ± 72.684 ns/op | ||
Benchmark.tomlktWithSerializer avgt 10 10901.727 ± 1002.641 ns/op | ||
Benchmark.toml4j avgt 10 20390.178 ± 251.729 ns/op | ||
Benchmark.ktomlWithSerializer avgt 10 46123.130 ± 1389.639 ns/op | ||
Benchmark.ktomlWithoutSerializer avgt 10 46555.647 ± 1047.836 ns/op | ||
*/ | ||
@BenchmarkMode(Mode.AverageTime) | ||
@Warmup(iterations = 4) | ||
@Measurement(iterations = 5) | ||
@Threads(4) | ||
@Fork(2) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Thread) | ||
class Benchmark { | ||
@Benchmark | ||
fun tomlktWithoutSerializer() { | ||
TomlObjects.tomlkt.decodeFromString<Config>(SampleConfig) | ||
} | ||
|
||
@Benchmark | ||
fun tomlktWithSerializer() { | ||
TomlObjects.tomlkt.decodeFromString(Config.serializer(), SampleConfig) | ||
} | ||
|
||
@Benchmark | ||
fun toml4j() { | ||
TomlObjects.toml4j.read(SampleConfig).to(Config::class.java) | ||
} | ||
|
||
@Benchmark | ||
fun ktomlWithoutSerializer() { | ||
TomlObjects.ktoml.decodeFromString<Config>(SampleConfig) | ||
} | ||
|
||
@Benchmark | ||
fun ktomlWithSerializer() { | ||
TomlObjects.ktoml.decodeFromString(Config.serializer(), SampleConfig) | ||
} | ||
|
||
@Benchmark | ||
fun jacksonWithClass() { | ||
TomlObjects.jackson.readValue(SampleConfig, Config::class.java) | ||
} | ||
|
||
@Benchmark | ||
fun jacksonWithType() { | ||
TomlObjects.jackson.readValue<Config>(SampleConfig) | ||
} | ||
} |
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,87 @@ | ||
package test | ||
|
||
import kotlinx.datetime.serializers.InstantIso8601Serializer | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import net.peanuuutz.tomlkt.TomlDecoder | ||
import net.peanuuutz.tomlkt.TomlOffsetDateTimeSerializer | ||
import org.intellij.lang.annotations.Language | ||
|
||
@Serializable | ||
data class Config( | ||
val title: String, | ||
val owner: Owner, | ||
val database: Database, | ||
// val servers: Map<String, Server> | ||
) | ||
|
||
@Serializable | ||
data class Owner( | ||
val name: String, | ||
val birthday: @Serializable(OffsetDateTimeSerializer::class) Any | ||
) | ||
|
||
@Serializable | ||
data class Database( | ||
val enabled: Boolean, | ||
val ports: List<Short>, | ||
val temperature: Temperature | ||
) | ||
|
||
@Serializable | ||
data class Temperature( | ||
val cpu: Float, | ||
val case: Float | ||
) | ||
|
||
@Serializable | ||
data class Server( | ||
val ip: String, | ||
val role: String | ||
) | ||
|
||
@Language("toml") | ||
const val SampleConfig: String = """ | ||
# This is a TOML document | ||
title = "TOML Example" | ||
[owner] | ||
name = "Tom Preston-Werner" | ||
birthday = 1979-05-27T07:32:00-08:00 | ||
[database] | ||
enabled = true | ||
ports = [ 8000, 8001, 8002 ] | ||
temperature = { cpu = 79.5, case = 72.0 } | ||
# [servers] | ||
# [servers.alpha] | ||
# ip = "10.0.0.1" | ||
# role = "frontend" | ||
# [servers.beta] | ||
# ip = "10.0.0.2" | ||
# role = "backend" | ||
""" | ||
|
||
object OffsetDateTimeSerializer : KSerializer<Any> { | ||
override val descriptor: SerialDescriptor | ||
get() = InstantIso8601Serializer.descriptor | ||
|
||
override fun serialize(encoder: Encoder, value: Any) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): Any { | ||
return if (decoder is TomlDecoder) { | ||
TomlOffsetDateTimeSerializer().deserialize(decoder) | ||
} else { | ||
InstantIso8601Serializer.deserialize(decoder) | ||
} | ||
} | ||
} |
Oops, something went wrong.