|
| 1 | +/* |
| 2 | + * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | + */ |
| 4 | + |
| 5 | +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| 6 | + |
| 7 | +plugins { |
| 8 | + id("net.ltgt.apt") |
| 9 | + id("com.github.johnrengelman.shadow") |
| 10 | + id("me.champeau.gradle.jmh") |
| 11 | +} |
| 12 | + |
| 13 | +repositories { |
| 14 | + maven("https://repo.typesafe.com/typesafe/releases/") |
| 15 | +} |
| 16 | + |
| 17 | +tasks.withType<KotlinCompile>().configureEach { |
| 18 | + kotlinOptions.jvmTarget = "1.8" |
| 19 | +} |
| 20 | + |
| 21 | +tasks.compileJmhKotlin { |
| 22 | + kotlinOptions.freeCompilerArgs += "-Xjvm-default=enable" |
| 23 | +} |
| 24 | + |
| 25 | +/* |
| 26 | + * Due to a bug in the inliner it sometimes does not remove inlined symbols (that are later renamed) from unused code paths, |
| 27 | + * and it breaks JMH that tries to post-process these symbols and fails because they are renamed. |
| 28 | + */ |
| 29 | +val removeRedundantFiles = tasks.register<Delete>("removeRedundantFiles") { |
| 30 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class") |
| 31 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$nBlanks\$1\$\$special\$\$inlined\$map\$1\$1.class") |
| 32 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$score2\$1\$\$special\$\$inlined\$map\$1\$1.class") |
| 33 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$bonusForDoubleLetter\$1\$\$special\$\$inlined\$map\$1\$1.class") |
| 34 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$nBlanks\$1\$\$special\$\$inlined\$map\$1\$2\$1.class") |
| 35 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$bonusForDoubleLetter\$1\$\$special\$\$inlined\$map\$1\$2\$1.class") |
| 36 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$score2\$1\$\$special\$\$inlined\$map\$1\$2\$1.class") |
| 37 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOptKt\$\$special\$\$inlined\$collect\$1\$1.class") |
| 38 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOptKt\$\$special\$\$inlined\$collect\$2\$1.class") |
| 39 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$histoOfLetters\$1\$\$special\$\$inlined\$fold\$1\$1.class") |
| 40 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleBase\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class") |
| 41 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleBase\$play\$histoOfLetters\$1\$\$special\$\$inlined\$fold\$1\$1.class") |
| 42 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble//SaneFlowPlaysScrabble\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class") |
| 43 | + |
| 44 | + // Primes |
| 45 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/misc/Numbers\$\$special\$\$inlined\$filter\$1\$2\$1.class") |
| 46 | + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/misc/Numbers\$\$special\$\$inlined\$filter\$1\$1.class") |
| 47 | +} |
| 48 | + |
| 49 | +tasks.jmhRunBytecodeGenerator { |
| 50 | + dependsOn(removeRedundantFiles) |
| 51 | +} |
| 52 | + |
| 53 | +// It is better to use the following to run benchmarks, otherwise you may get unexpected errors: |
| 54 | +// ./gradlew --no-daemon cleanJmhJar jmh -Pjmh="MyBenchmark" |
| 55 | +jmh { |
| 56 | + jmhVersion = "1.21" |
| 57 | + duplicateClassesStrategy = DuplicatesStrategy.INCLUDE |
| 58 | + failOnError = true |
| 59 | + resultFormat = "CSV" |
| 60 | + project.findProperty("jmh")?.also { |
| 61 | + include = listOf(".*$it.*") |
| 62 | + } |
| 63 | +// includeTests = false |
| 64 | +} |
| 65 | + |
| 66 | +tasks.jmhJar { |
| 67 | + baseName = "benchmarks" |
| 68 | + classifier = null |
| 69 | + version = null |
| 70 | + destinationDir = file("$rootDir") |
| 71 | +} |
| 72 | + |
| 73 | +dependencies { |
| 74 | + compile("org.openjdk.jmh:jmh-core:1.21") |
| 75 | + compile("io.projectreactor:reactor-core:${property("reactor_vesion")}") |
| 76 | + compile("io.reactivex.rxjava2:rxjava:2.1.9") |
| 77 | + compile("com.github.akarnokd:rxjava2-extensions:0.20.8") |
| 78 | + |
| 79 | + compile("org.openjdk.jmh:jmh-core:1.21") |
| 80 | + compile("com.typesafe.akka:akka-actor_2.12:2.5.0") |
| 81 | + compile(project(":kotlinx-coroutines-core")) |
| 82 | + |
| 83 | + // add jmh dependency on main |
| 84 | + jmhImplementation(sourceSets.main.get().runtimeClasspath) |
| 85 | +} |
0 commit comments