Skip to content

Commit d733b68

Browse files
turanskyrecheej
authored andcommitted
Restore java configuration for 'benchmarks' (Kotlin#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'
1 parent 7a321b3 commit d733b68

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

benchmarks/build.gradle.kts

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@
22
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
5+
import me.champeau.gradle.*
6+
import org.jetbrains.kotlin.gradle.tasks.*
67

78
plugins {
89
id("net.ltgt.apt")
910
id("com.github.johnrengelman.shadow")
10-
id("me.champeau.gradle.jmh")
11+
id("me.champeau.gradle.jmh") apply false
1112
}
1213

1314
repositories {
1415
maven("https://repo.typesafe.com/typesafe/releases/")
1516
}
1617

17-
tasks.withType<KotlinCompile>().configureEach {
18-
kotlinOptions.jvmTarget = "1.8"
18+
java {
19+
sourceCompatibility = JavaVersion.VERSION_1_8
20+
targetCompatibility = JavaVersion.VERSION_1_8
1921
}
2022

21-
tasks.compileJmhKotlin {
22-
kotlinOptions.freeCompilerArgs += "-Xjvm-default=enable"
23+
apply(plugin="me.champeau.gradle.jmh")
24+
25+
tasks.named<KotlinCompile>("compileJmhKotlin") {
26+
kotlinOptions {
27+
jvmTarget = "1.8"
28+
freeCompilerArgs += "-Xjvm-default=enable"
29+
}
2330
}
2431

2532
/*
@@ -39,20 +46,20 @@ val removeRedundantFiles = tasks.register<Delete>("removeRedundantFiles") {
3946
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleOpt\$play\$histoOfLetters\$1\$\$special\$\$inlined\$fold\$1\$1.class")
4047
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/FlowPlaysScrabbleBase\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class")
4148
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")
49+
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/scrabble/SaneFlowPlaysScrabble\$play\$buildHistoOnScore\$1\$\$special\$\$inlined\$filter\$1\$1.class")
4350

4451
// Primes
4552
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/misc/Numbers\$\$special\$\$inlined\$filter\$1\$2\$1.class")
4653
delete("$buildDir/classes/kotlin/jmh/benchmarks/flow/misc/Numbers\$\$special\$\$inlined\$filter\$1\$1.class")
4754
}
4855

49-
tasks.jmhRunBytecodeGenerator {
56+
tasks.named("jmhRunBytecodeGenerator") {
5057
dependsOn(removeRedundantFiles)
5158
}
5259

5360
// It is better to use the following to run benchmarks, otherwise you may get unexpected errors:
5461
// ./gradlew --no-daemon cleanJmhJar jmh -Pjmh="MyBenchmark"
55-
jmh {
62+
extensions.configure<JMHPluginExtension>("jmh") {
5663
jmhVersion = "1.21"
5764
duplicateClassesStrategy = DuplicatesStrategy.INCLUDE
5865
failOnError = true
@@ -63,7 +70,7 @@ jmh {
6370
// includeTests = false
6471
}
6572

66-
tasks.jmhJar {
73+
tasks.named<Jar>("jmhJar") {
6774
baseName = "benchmarks"
6875
classifier = null
6976
version = null
@@ -76,10 +83,9 @@ dependencies {
7683
compile("io.reactivex.rxjava2:rxjava:2.1.9")
7784
compile("com.github.akarnokd:rxjava2-extensions:0.20.8")
7885

79-
compile("org.openjdk.jmh:jmh-core:1.21")
8086
compile("com.typesafe.akka:akka-actor_2.12:2.5.0")
8187
compile(project(":kotlinx-coroutines-core"))
8288

8389
// add jmh dependency on main
84-
jmhImplementation(sourceSets.main.get().runtimeClasspath)
90+
"jmhImplementation"(sourceSets.main.get().runtimeClasspath)
8591
}

benchmarks/src/jmh/kotlin/benchmarks/flow/FlowFlattenMergeBenchmark.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import benchmarks.common.*
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010
import org.openjdk.jmh.annotations.*
11-
import java.util.concurrent.*
11+
import java.util.concurrent.TimeUnit
1212

1313
/**
1414
* Benchmark to measure performance of [kotlinx.coroutines.flow.FlowKt.flattenMerge].

benchmarks/src/jmh/kotlin/benchmarks/flow/NumbersBenchmark.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import io.reactivex.functions.*
1111
import kotlinx.coroutines.*
1212
import kotlinx.coroutines.flow.*
1313
import org.openjdk.jmh.annotations.*
14-
import java.util.concurrent.*
14+
import java.util.concurrent.TimeUnit
15+
import java.util.concurrent.Callable
1516

1617
@Warmup(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS)
1718
@Measurement(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS)

benchmarks/src/jmh/kotlin/benchmarks/flow/TakeBenchmark.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package benchmarks.flow
77
import kotlinx.coroutines.*
88
import kotlinx.coroutines.flow.*
99
import org.openjdk.jmh.annotations.*
10-
import java.util.concurrent.*
10+
import java.util.concurrent.TimeUnit
1111
import java.util.concurrent.CancellationException
1212
import kotlin.coroutines.*
1313
import kotlin.coroutines.intrinsics.*

benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/FlowPlaysScrabbleBase.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.*
99
import org.openjdk.jmh.annotations.*
1010
import java.lang.Long.max
1111
import java.util.*
12-
import java.util.concurrent.*
12+
import java.util.concurrent.TimeUnit
1313
import kotlin.math.*
1414

1515
@Warmup(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS)

benchmarks/src/jmh/kotlin/benchmarks/flow/scrabble/SaneFlowPlaysScrabble.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.*
99
import org.openjdk.jmh.annotations.*
1010
import java.lang.Long.*
1111
import java.util.*
12-
import java.util.concurrent.*
12+
import java.util.concurrent.TimeUnit
1313

1414
@Warmup(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS)
1515
@Measurement(iterations = 7, time = 1, timeUnit = TimeUnit.SECONDS)

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pluginManagement {
88

99
// JMH
1010
id "net.ltgt.apt" version "0.21"
11-
id "me.champeau.gradle.jmh" version "0.5.0-rc-2"
11+
id "me.champeau.gradle.jmh" version "0.5.0"
1212
}
1313
}
1414

0 commit comments

Comments
 (0)