Skip to content

Commit

Permalink
Restore java configuration for 'benchmarks' (#2027)
Browse files Browse the repository at this point in the history
* 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'
  • Loading branch information
turansky authored May 15, 2020
1 parent 559023d commit 4511c23
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
30 changes: 18 additions & 12 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<KotlinCompile>().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<KotlinCompile>("compileJmhKotlin") {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xjvm-default=enable"
}
}

/*
Expand All @@ -39,20 +46,20 @@ val removeRedundantFiles = tasks.register<Delete>("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<JMHPluginExtension>("jmh") {
jmhVersion = "1.21"
duplicateClassesStrategy = DuplicatesStrategy.INCLUDE
failOnError = true
Expand All @@ -63,7 +70,7 @@ jmh {
// includeTests = false
}

tasks.jmhJar {
tasks.named<Jar>("jmhJar") {
baseName = "benchmarks"
classifier = null
version = null
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/jmh/kotlin/benchmarks/flow/TakeBenchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down

0 comments on commit 4511c23

Please # to comment.