blob: 8595c02f5ad599f8f6c5817659275c18cb4a9fda [file] [log] [blame]
James Kuszmaul8e62b022022-03-22 09:33:25 -07001import org.jetbrains.kotlin.ir.backend.js.compile
2
3plugins {
Austin Schuh2dd86a92022-09-14 21:19:23 -07004 kotlin("multiplatform")
James Kuszmaul8e62b022022-03-22 09:33:25 -07005 id("org.jetbrains.kotlin.plugin.allopen") version "1.4.20"
Austin Schuh2dd86a92022-09-14 21:19:23 -07006 id("org.jetbrains.kotlinx.benchmark") version "0.4.2"
James Kuszmaul8e62b022022-03-22 09:33:25 -07007 id("io.morethan.jmhreport") version "0.9.0"
Austin Schuh2dd86a92022-09-14 21:19:23 -07008 id("de.undercouch.download")
James Kuszmaul8e62b022022-03-22 09:33:25 -07009}
10
11// allOpen plugin is needed for the benchmark annotations.
Austin Schuh2dd86a92022-09-14 21:19:23 -070012// for more information, see https://github.com/Kotlin/kotlinx-benchmark#gradle-plugin
James Kuszmaul8e62b022022-03-22 09:33:25 -070013allOpen {
14 annotation("org.openjdk.jmh.annotations.State")
15}
16
17group = "com.google.flatbuffers.jmh"
18version = "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.
22jmhReport {
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
30benchmark {
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
45kotlin {
46 jvm {
47 withJava()
James Kuszmaul8e62b022022-03-22 09:33:25 -070048 }
49
50 sourceSets {
51
52 all {
53 languageSettings.enableLanguageFeature("InlineClasses")
James Kuszmaul8e62b022022-03-22 09:33:25 -070054 }
55
James Kuszmaul8e62b022022-03-22 09:33:25 -070056 val jvmMain by getting {
57 dependencies {
James Kuszmaul8e62b022022-03-22 09:33:25 -070058 implementation(kotlin("stdlib-common"))
59 implementation(project(":flatbuffers-kotlin"))
Austin Schuh2dd86a92022-09-14 21:19:23 -070060 implementation(libs.kotlinx.benchmark.runtime)
James Kuszmaul8e62b022022-03-22 09:33:25 -070061
Austin Schuh2dd86a92022-09-14 21:19:23 -070062 // json serializers
63 implementation(libs.moshi.kotlin)
64 implementation(libs.gson)
James Kuszmaul8e62b022022-03-22 09:33:25 -070065 }
66 }
James Kuszmaul8e62b022022-03-22 09:33:25 -070067 }
68}
69
70// This task download all JSON files used for benchmarking
71tasks.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}