1 import org.jetbrains.kotlin.ir.backend.js.compile 2 <lambda>null3plugins { 4 kotlin("multiplatform") 5 id("org.jetbrains.kotlin.plugin.allopen") version "1.4.20" 6 id("org.jetbrains.kotlinx.benchmark") version "0.4.2" 7 id("io.morethan.jmhreport") version "0.9.0" 8 id("de.undercouch.download") 9 } 10 11 // allOpen plugin is needed for the benchmark annotations. 12 // for more information, see https://github.com/Kotlin/kotlinx-benchmark#gradle-plugin <lambda>null13allOpen { 14 annotation("org.openjdk.jmh.annotations.State") 15 } 16 17 group = "com.google.flatbuffers.jmh" 18 version = "2.0.0-SNAPSHOT" 19 20 // This plugin generates a static html page with the aggregation 21 // of all benchmarks ran. very useful visualization tool. <lambda>null22jmhReport { 23 val baseFolder = project.file("build/reports/benchmarks/main").absolutePath 24 val lastFolder = project.file(baseFolder).list()?.sortedArray()?.lastOrNull() ?: "" 25 jmhResultPath = "$baseFolder/$lastFolder/jvm.json" 26 jmhReportOutput = "$baseFolder/$lastFolder" 27 } 28 29 // For now we benchmark on JVM only <lambda>null30benchmark { 31 configurations { 32 this.getByName("main") { 33 iterations = 5 34 iterationTime = 300 35 iterationTimeUnit = "ms" 36 // uncomment for benchmarking JSON op only 37 // include(".*JsonBenchmark.*") 38 } 39 } 40 targets { 41 register("jvm") 42 } 43 } 44 <lambda>null45kotlin { 46 jvm { 47 withJava() 48 } 49 50 sourceSets { 51 52 all { 53 languageSettings.enableLanguageFeature("InlineClasses") 54 } 55 56 val jvmMain by getting { 57 dependencies { 58 implementation(kotlin("stdlib-common")) 59 implementation(project(":flatbuffers-kotlin")) 60 implementation(libs.kotlinx.benchmark.runtime) 61 62 // json serializers 63 implementation(libs.moshi.kotlin) 64 implementation(libs.gson) 65 } 66 } 67 } 68 } 69 70 // This task download all JSON files used for benchmarking <lambda>null71tasks.register<de.undercouch.gradle.tasks.download.Download>("downloadMultipleFiles") { 72 // We are downloading json benchmark samples from serdes-rs project. 73 // see: https://github.com/serde-rs/json-benchmark/blob/master/data 74 val baseUrl = "https://github.com/serde-rs/json-benchmark/raw/master/data/" 75 src(listOf("$baseUrl/canada.json", "$baseUrl/twitter.json", "$baseUrl/citm_catalog.json")) 76 dest(File("${project.projectDir.absolutePath}/src/jvmMain/resources")) 77 overwrite(false) 78 } 79