summaryrefslogtreecommitdiff
path: root/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'kotlin')
-rw-r--r--kotlin/benchmark/build.gradle.kts19
-rw-r--r--kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/FlexBuffersBenchmark.kt21
-rw-r--r--kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/JsonBenchmark.kt38
-rw-r--r--kotlin/build.gradle.kts27
-rw-r--r--kotlin/gradle/libs.versions.toml17
-rw-r--r--kotlin/gradle/wrapper/gradle-wrapper.properties2
6 files changed, 47 insertions, 77 deletions
diff --git a/kotlin/benchmark/build.gradle.kts b/kotlin/benchmark/build.gradle.kts
index 8595c02f..976cb7bb 100644
--- a/kotlin/benchmark/build.gradle.kts
+++ b/kotlin/benchmark/build.gradle.kts
@@ -2,18 +2,11 @@ import org.jetbrains.kotlin.ir.backend.js.compile
plugins {
kotlin("multiplatform")
- id("org.jetbrains.kotlin.plugin.allopen") version "1.4.20"
- id("org.jetbrains.kotlinx.benchmark") version "0.4.2"
- id("io.morethan.jmhreport") version "0.9.0"
+ id("org.jetbrains.kotlinx.benchmark")
+ id("io.morethan.jmhreport")
id("de.undercouch.download")
}
-// allOpen plugin is needed for the benchmark annotations.
-// for more information, see https://github.com/Kotlin/kotlinx-benchmark#gradle-plugin
-allOpen {
- annotation("org.openjdk.jmh.annotations.State")
-}
-
group = "com.google.flatbuffers.jmh"
version = "2.0.0-SNAPSHOT"
@@ -34,7 +27,7 @@ benchmark {
iterationTime = 300
iterationTimeUnit = "ms"
// uncomment for benchmarking JSON op only
- // include(".*JsonBenchmark.*")
+ include(".*JsonBenchmark.*")
}
}
targets {
@@ -43,9 +36,7 @@ benchmark {
}
kotlin {
- jvm {
- withJava()
- }
+ jvm()
sourceSets {
@@ -58,7 +49,7 @@ kotlin {
implementation(kotlin("stdlib-common"))
implementation(project(":flatbuffers-kotlin"))
implementation(libs.kotlinx.benchmark.runtime)
-
+ implementation("com.google.flatbuffers:flatbuffers-java:2.0.3")
// json serializers
implementation(libs.moshi.kotlin)
implementation(libs.gson)
diff --git a/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/FlexBuffersBenchmark.kt b/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/FlexBuffersBenchmark.kt
index ade57d95..99088aa0 100644
--- a/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/FlexBuffersBenchmark.kt
+++ b/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/FlexBuffersBenchmark.kt
@@ -14,7 +14,6 @@
* limitations under the License.
*/
package com.google.flatbuffers.kotlin.benchmark
-
import com.google.flatbuffers.ArrayReadWriteBuf
import com.google.flatbuffers.FlexBuffers
import com.google.flatbuffers.FlexBuffersBuilder.BUILDER_FLAG_SHARE_ALL
@@ -35,7 +34,7 @@ import java.util.concurrent.TimeUnit
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.NANOSECONDS)
-class FlexBuffersBenchmark {
+open class FlexBuffersBenchmark {
var initialCapacity = 1024
var value: Double = 0.0
@@ -49,7 +48,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun mapKotlin(blackhole: Blackhole) {
+ open fun mapKotlin(blackhole: Blackhole) {
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
kBuilder.putMap {
this["hello"] = "world"
@@ -72,7 +71,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun mapJava(blackhole: Blackhole) {
+ open fun mapJava(blackhole: Blackhole) {
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
val startMap = jBuilder.startMap()
jBuilder.putString("hello", "world")
@@ -102,7 +101,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun intArrayKotlin(blackhole: Blackhole) {
+ open fun intArrayKotlin(blackhole: Blackhole) {
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
kBuilder.put(bigIntArray)
val root = getRoot(kBuilder.finish())
@@ -110,7 +109,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun intArrayJava(blackhole: Blackhole) {
+ open fun intArrayJava(blackhole: Blackhole) {
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
val v = jBuilder.startVector()
bigIntArray.forEach { jBuilder.putInt(it) }
@@ -126,7 +125,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun stringArrayKotlin(blackhole: Blackhole) {
+ open fun stringArrayKotlin(blackhole: Blackhole) {
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
kBuilder.putVector { stringValue.forEach { kBuilder.put(it) } }
kBuilder.finish()
@@ -136,7 +135,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun stringArrayJava(blackhole: Blackhole) {
+ open fun stringArrayJava(blackhole: Blackhole) {
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
val v = jBuilder.startVector()
stringValue.forEach { jBuilder.putString(it) }
@@ -148,7 +147,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun stringMapKotlin(blackhole: Blackhole) {
+ open fun stringMapKotlin(blackhole: Blackhole) {
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
val pos = kBuilder.startMap()
for (i in stringKey.indices) {
@@ -165,7 +164,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun stringMapBytIndexKotlin(blackhole: Blackhole) {
+ open fun stringMapBytIndexKotlin(blackhole: Blackhole) {
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
val pos = kBuilder.startMap()
for (i in stringKey.indices) {
@@ -180,7 +179,7 @@ class FlexBuffersBenchmark {
}
@Benchmark
- fun stringMapJava(blackhole: Blackhole) {
+ open fun stringMapJava(blackhole: Blackhole) {
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
val v = jBuilder.startMap()
for (i in stringKey.indices) {
diff --git a/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/JsonBenchmark.kt b/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/JsonBenchmark.kt
index 7d2ae507..ad7688e8 100644
--- a/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/JsonBenchmark.kt
+++ b/kotlin/benchmark/src/jvmMain/kotlin/com/google/flatbuffers/kotlin/benchmark/JsonBenchmark.kt
@@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Measurement(iterations = 100, time = 1, timeUnit = TimeUnit.MICROSECONDS)
-class JsonBenchmark {
+open class JsonBenchmark {
final val moshi = Moshi.Builder()
.addLast(KotlinJsonAdapterFactory())
@@ -76,46 +76,46 @@ class JsonBenchmark {
// TWITTER
@Benchmark
- fun readTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData))
+ open fun readTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData))
@Benchmark
- fun readTwitterMoshi(hole: Blackhole?) = hole?.consume(readMoshi(twitterData))
+ open fun readTwitterMoshi(hole: Blackhole?) = hole?.consume(readMoshi(twitterData))
@Benchmark
- fun readTwitterGson(hole: Blackhole?) = hole?.consume(readGson(twitterData))
+ open fun readTwitterGson(hole: Blackhole?) = hole?.consume(readGson(twitterData))
@Benchmark
- fun roundTripTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData).toJson())
+ open fun roundTripTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData).toJson())
@Benchmark
- fun roundTripTwitterMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(twitterData)))
+ open fun roundTripTwitterMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(twitterData)))
@Benchmark
- fun roundTripTwitterGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(twitterData)))
+ open fun roundTripTwitterGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(twitterData)))
// CITM
@Benchmark
- fun readCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData))
+ open fun readCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData))
@Benchmark
- fun readCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
+ open fun readCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
@Benchmark
- fun readCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
+ open fun readCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
@Benchmark
- fun roundTripCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData).toJson())
+ open fun roundTripCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData).toJson())
@Benchmark
- fun roundTripCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
+ open fun roundTripCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
@Benchmark
- fun roundTripCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
+ open fun roundTripCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
@Benchmark
- fun writeCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(fbCitmRef.toJson())
+ open fun writeCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(fbCitmRef.toJson())
@Benchmark
- fun writeCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(moshiCitmRef))
+ open fun writeCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(moshiCitmRef))
@Benchmark
- fun writeCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(gsonCitmRef))
+ open fun writeCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(gsonCitmRef))
// CANADA
@Benchmark
- fun readCanadaFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(canadaData))
+ open fun readCanadaFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(canadaData))
@Benchmark
- fun readCanadaMoshi(hole: Blackhole?) = hole?.consume(readMoshi(canadaData))
+ open fun readCanadaMoshi(hole: Blackhole?) = hole?.consume(readMoshi(canadaData))
@Benchmark
- fun readCanadaGson(hole: Blackhole?) = hole?.consume(readGson(canadaData))
+ open fun readCanadaGson(hole: Blackhole?) = hole?.consume(readGson(canadaData))
}
diff --git a/kotlin/build.gradle.kts b/kotlin/build.gradle.kts
index b1890756..8778c866 100644
--- a/kotlin/build.gradle.kts
+++ b/kotlin/build.gradle.kts
@@ -1,7 +1,3 @@
-plugins {
- id("com.diffplug.spotless") version "6.3.0"
-}
-
group = "com.google.flatbuffers"
version = "2.0.0-SNAPSHOT"
@@ -12,7 +8,10 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath(libs.bundles.plugins)
+ classpath(libs.plugin.kotlin.gradle)
+ classpath(libs.plugin.kotlinx.benchmark)
+ classpath(libs.plugin.jmhreport)
+ classpath(libs.plugin.download)
}
}
@@ -22,21 +21,3 @@ allprojects {
mavenCentral()
}
}
-
-// plugin used to enforce code style
-spotless {
- val klintConfig = mapOf("indent_size" to "2", "continuation_indent_size" to "2")
- kotlin {
- target("**/*.kt")
- ktlint("0.40.0").userData(klintConfig)
- trimTrailingWhitespace()
- indentWithSpaces()
- endWithNewline()
- licenseHeaderFile("$rootDir/spotless/spotless.kt").updateYearWithLatest(false)
- targetExclude("**/spotless.kt", "**/build/**")
- }
- kotlinGradle {
- target("*.gradle.kts")
- ktlint().userData(klintConfig)
- }
-}
diff --git a/kotlin/gradle/libs.versions.toml b/kotlin/gradle/libs.versions.toml
index 089f7e78..e3230b7d 100644
--- a/kotlin/gradle/libs.versions.toml
+++ b/kotlin/gradle/libs.versions.toml
@@ -1,20 +1,19 @@
[versions]
-plugin-kotlin = "1.6.10"
+kotlin = "1.7.21"
plugin-gver = "0.42.0"
-kotlinx-benchmark-runtime = "0.4.2"
+kotlinx-benchmark = "0.4.6"
junit = "4.12"
gson = "2.8.5"
moshi-kotlin = "1.11.0"
[libraries]
+kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin" }
moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi-kotlin" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
-kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark-runtime" }
-plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "plugin-kotlin" }
-plugin-kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "plugin-kotlin" }
+kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }
plugin-gver = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "plugin-gver" }
-
+plugin-kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
+plugin-kotlinx-benchmark = { module="org.jetbrains.kotlinx:kotlinx-benchmark-plugin", version.ref="kotlinx-benchmark"}
+plugin-jmhreport = { module = "gradle.plugin.io.morethan.jmhreport:gradle-jmh-report", version="0.9.0" }
+plugin-download = { module = "de.undercouch:gradle-download-task", version = "5.3.0"}
junit = { module="junit:junit", version.ref="junit"}
-
-[bundles]
-plugins = ["plugin-kotlin", "plugin-kotlin-serialization", "plugin-gver"]
diff --git a/kotlin/gradle/wrapper/gradle-wrapper.properties b/kotlin/gradle/wrapper/gradle-wrapper.properties
index aa991fce..f72df95a 100644
--- a/kotlin/gradle/wrapper/gradle-wrapper.properties
+++ b/kotlin/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists