From 4511c23ec04c6052d3f85ea8085afc407aebfb36 Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Fri, 15 May 2020 12:00:36 +0300 Subject: [PATCH] Restore java configuration for 'benchmarks' (#2027) * Restore java configuration for 'benchmarks' * Apply 'jmh' plugin after java configuration * Specify java.util.concurrent imports after migration to Java 11 * Remove duplicated dependency * Use release version of 'jmh' plugin. '0.5.0-rc-2' -> '0.5.0' --- benchmarks/build.gradle.kts | 30 +++++++++++-------- .../flow/FlowFlattenMergeBenchmark.kt | 2 +- .../benchmarks/flow/NumbersBenchmark.kt | 3 +- .../kotlin/benchmarks/flow/TakeBenchmark.kt | 2 +- .../flow/scrabble/FlowPlaysScrabbleBase.kt | 2 +- .../flow/scrabble/SaneFlowPlaysScrabble.kt | 2 +- settings.gradle | 2 +- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index fa651346ce..7df4510bf4 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -2,24 +2,31 @@ * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import me.champeau.gradle.* +import org.jetbrains.kotlin.gradle.tasks.* plugins { id("net.ltgt.apt") id("com.github.johnrengelman.shadow") - id("me.champeau.gradle.jmh") + id("me.champeau.gradle.jmh") apply false } repositories { maven("https://repo.typesafe.com/typesafe/releases/") } -tasks.withType().configureEach { - kotlinOptions.jvmTarget = "1.8" +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } -tasks.compileJmhKotlin { - kotlinOptions.freeCompilerArgs += "-Xjvm-default=enable" +apply(plugin="me.champeau.gradle.jmh") + +tasks.named("compileJmhKotlin") { + kotlinOptions { + jvmTarget = "1.8" + freeCompilerArgs += "-Xjvm-default=enable" + } } /* @@ -39,20 +46,20 @@ val removeRedundantFiles = tasks.register("removeRedundantFiles") { delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$histoOfLetters\$1\$\$special\$\$inlined\$fold\$1\$1.class") delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleBase\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class") delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleBase\$play\$histoOfLetters\$1\$\$special\$\$inlined\$fold\$1\$1.class") - delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble//SaneFlowPlaysScrabble\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class") + delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/SaneFlowPlaysScrabble\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class") // Primes delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/misc/Numbers\$\$special\$\$inlined\$filter\$1\$2\$1.class") delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/misc/Numbers\$\$special\$\$inlined\$filter\$1\$1.class") } -tasks.jmhRunBytecodeGenerator { +tasks.named("jmhRunBytecodeGenerator") { dependsOn(removeRedundantFiles) } // It is better to use the following to run benchmarks, otherwise you may get unexpected errors: // ./gradlew --no-daemon cleanJmhJar jmh -Pjmh="MyBenchmark" -jmh { +extensions.configure("jmh") { jmhVersion = "1.21" duplicateClassesStrategy = DuplicatesStrategy.INCLUDE failOnError = true @@ -63,7 +70,7 @@ jmh { // includeTests = false } -tasks.jmhJar { +tasks.named("jmhJar") { baseName = "benchmarks" classifier = null version = null @@ -76,10 +83,9 @@ dependencies { compile("io.reactivex.rxjava2:rxjava:2.1.9") compile("com.github.akarnokd:rxjava2-extensions:0.20.8") - compile("org.openjdk.jmh:jmh-core:1.21") compile("com.typesafe.akka:akka-actor_2.12:2.5.0") compile(project(":kotlinx-coroutines-core")) // add jmh dependency on main - jmhImplementation(sourceSets.main.get().runtimeClasspath) + "jmhImplementation"(sourceSets.main.get().runtimeClasspath) } diff --git a/benchmarks/src/jmh/kotlin/benchmarks/flow/FlowFlattenMergeBenchmark.kt b/benchmarks/src/jmh/kotlin/benchmarks/flow/FlowFlattenMergeBenchmark.kt index 3fff2697cc..149898881b 100644 --- a/benchmarks/src/jmh/kotlin/benchmarks/flow/FlowFlattenMergeBenchmark.kt +++ b/benchmarks/src/jmh/kotlin/benchmarks/flow/FlowFlattenMergeBenchmark.kt @@ -8,7 +8,7 @@ import benchmarks.common.* import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import org.openjdk.jmh.annotations.* -import java.util.concurrent.* +import java.util.concurrent.TimeUnit /** * Benchmark to measure performance of [kotlinx.coroutines.flow.FlowKt.flattenMerge]. diff --git a/benchmarks/src/jmh/kotlin/benchmarks/flow/NumbersBenchmark.kt b/benchmarks/src/jmh/kotlin/benchmarks/flow/NumbersBenchmark.kt index 0cb31056bb..4ebb3d07ff 100644 --- a/benchmarks/src/jmh/kotlin/benchmarks/flow/NumbersBenchmark.kt +++ b/benchmarks/src/jmh/kotlin/benchmarks/flow/NumbersBenchmark.kt @@ -11,7 +11,8 @@ import io.reactivex.functions.* import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import org.openjdk.jmh.annotations.* -import java.util.concurrent.* +import java.util.concurrent.TimeUnit +import java.util.concurrent.Callable @Warmup(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS) diff --git a/benchmarks/src/jmh/kotlin/benchmarks/flow/TakeBenchmark.kt b/benchmarks/src/jmh/kotlin/benchmarks/flow/TakeBenchmark.kt index 1c469a69b9..1e12e2c33e 100644 --- a/benchmarks/src/jmh/kotlin/benchmarks/flow/TakeBenchmark.kt +++ b/benchmarks/src/jmh/kotlin/benchmarks/flow/TakeBenchmark.kt @@ -7,7 +7,7 @@ package benchmarks.flow import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import org.openjdk.jmh.annotations.* -import java.util.concurrent.* +import java.util.concurrent.TimeUnit import java.util.concurrent.CancellationException import kotlin.coroutines.* import kotlin.coroutines.intrinsics.* diff --git a/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/FlowPlaysScrabbleBase.kt b/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/FlowPlaysScrabbleBase.kt index 9e39b43b8b..3501bdfed3 100644 --- a/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/FlowPlaysScrabbleBase.kt +++ b/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/FlowPlaysScrabbleBase.kt @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.* import org.openjdk.jmh.annotations.* import java.lang.Long.max import java.util.* -import java.util.concurrent.* +import java.util.concurrent.TimeUnit import kotlin.math.* @Warmup(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS) diff --git a/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/SaneFlowPlaysScrabble.kt b/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/SaneFlowPlaysScrabble.kt index 0a4f69672f..ad97dfa373 100644 --- a/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/SaneFlowPlaysScrabble.kt +++ b/benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/SaneFlowPlaysScrabble.kt @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.* import org.openjdk.jmh.annotations.* import java.lang.Long.* import java.util.* -import java.util.concurrent.* +import java.util.concurrent.TimeUnit @Warmup(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS) diff --git a/settings.gradle b/settings.gradle index ae49f16d1d..d296c1eecc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { // JMH id "net.ltgt.apt" version "0.21" - id "me.champeau.gradle.jmh" version "0.5.0-rc-2" + id "me.champeau.gradle.jmh" version "0.5.0" } }