1 import org.jetbrains.kotlin.ir.backend.js.compile 2 <lambda>null3plugins { 4 kotlin("multiplatform") version "1.4.20" 5 id("org.jetbrains.kotlin.plugin.allopen") version "1.4.20" 6 id("org.jetbrains.kotlinx.benchmark") version "0.3.0" 7 id("io.morethan.jmhreport") version "0.9.0" 8 id("de.undercouch.download") version "4.1.1" 9 } 10 11 // allOpen plugin is needed for the benchmark annotations. 12 // for more infomation, 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 compilations.all { 49 kotlinOptions { 50 jvmTarget = JavaVersion.VERSION_1_8.toString() 51 } 52 } 53 } 54 55 sourceSets { 56 57 all { 58 languageSettings.enableLanguageFeature("InlineClasses") 59 languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") 60 } 61 62 val commonTest by getting { 63 dependencies { 64 implementation(kotlin("test-common")) 65 implementation(kotlin("test-annotations-common")) 66 } 67 } 68 val jvmTest by getting { 69 dependencies { 70 implementation(kotlin("test-junit")) 71 } 72 } 73 val jvmMain by getting { 74 dependencies { 75 implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.3.0") 76 implementation(kotlin("stdlib-common")) 77 implementation(project(":flatbuffers-kotlin")) 78 implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 79 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.1") 80 81 //moshi 82 implementation("com.squareup.moshi:moshi-kotlin:1.11.0") 83 84 //gson 85 implementation("com.google.code.gson:gson:2.8.5") 86 } 87 } 88 89 /* Targets configuration omitted. 90 * To find out how to configure the targets, please follow the link: 91 * https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets 92 */ 93 targets { 94 targetFromPreset(presets.getAt("jvm")) 95 } 96 } 97 } 98 99 // This task download all JSON files used for benchmarking <lambda>null100tasks.register<de.undercouch.gradle.tasks.download.Download>("downloadMultipleFiles") { 101 // We are downloading json benchmark samples from serdes-rs project. 102 // see: https://github.com/serde-rs/json-benchmark/blob/master/data 103 val baseUrl = "https://github.com/serde-rs/json-benchmark/raw/master/data/" 104 src(listOf("$baseUrl/canada.json", "$baseUrl/twitter.json", "$baseUrl/citm_catalog.json")) 105 dest(File("${project.projectDir.absolutePath}/src/jvmMain/resources")) 106 overwrite(false) 107 } 108 <lambda>null109project.tasks.named("compileKotlinJvm") { 110 dependsOn("downloadMultipleFiles") 111 } 112