Skip to content

Commit 6b17c0c

Browse files
committed
Fix samples, add main configuration by default, handle empty includes, configure mode & output time unit
1 parent 1bc8022 commit 6b17c0c

File tree

9 files changed

+52
-63
lines changed

9 files changed

+52
-63
lines changed

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ repositories {
5757
}
5858
```
5959

60-
> Please note that in this early project stage only macOS x64 binaries are published.
61-
If you need to run it on Linux or Windows, check out sources, update `build.gradle` for `runtime` project, and publish
62-
to Maven Local repository.
60+
# Configuring benchmark targets
6361

64-
# Configuring benchmark source sets
65-
66-
In a `build.gradle` file create ` benchmark` section, and inside it add a `configurations` section.
62+
In a `build.gradle` file create ` benchmark` section, and inside it add a `targets` section.
6763
Example for multiplatform project:
6864

6965
```groovy
7066
benchmark {
71-
configurations {
67+
targets {
7268
register("jvm")
7369
register("js")
7470
register("native")
@@ -80,7 +76,7 @@ Example for plain Java project:
8076

8177
```groovy
8278
benchmark {
83-
configurations {
79+
targets {
8480
register("main")
8581
}
8682
}
@@ -90,26 +86,31 @@ Configure benchmarks:
9086

9187
```groovy
9288
benchmark {
93-
defaults { // specify defaults for all configurations
94-
iterations = 10 // number of iterations
95-
iterationTime = 1000 // time in ms per iteration
89+
// Create configurations
90+
configurations {
91+
main { // main configuration is created automatically, but you can change its defaults
92+
iterations = 10 // number of iterations
93+
iterationTime = 3 // time in seconds per iteration
94+
}
95+
fast {
96+
warmups = 5 // number of warmup iterations
97+
iterations = 3 // number of iterations
98+
iterationTime = 500 // time in seconds per iteration
99+
iterationTimeUnit = "ms" // time unity for iterationTime, default is seconds
100+
}
96101
}
97102
98-
// Setup configurations
99-
configurations {
103+
// Setup targets
104+
targets {
100105
// This one matches compilation base name, e.g. 'jvm', 'jvmTest', etc
101106
register("jvm") {
102107
jmhVersion = "1.21" // available only for JVM compilations & Java source sets
103-
104-
// for now, we use iterations and iterationTime for both warmup and measurements
105108
}
106109
register("js") {
107110
// Note, that benchmarks.js uses a different approach of minTime & maxTime and run benchmarks
108111
// until results are stable. We estimate minTime as iterationTime and maxTime as iterationTime*iterations
109112
}
110-
register("native") {
111-
iterationTime = 2000 // override the default
112-
}
113+
register("native")
113114
}
114115
}
115116
```
@@ -129,7 +130,7 @@ Propagate dependencies and output from `main` sourceSet.
129130

130131
```groovy
131132
dependencies {
132-
benchmarksCompile sourceSets.main.output + sourceSets.main.compileClasspath
133+
benchmarksCompile sourceSets.main.output + sourceSets.main.runtimeClasspath
133134
}
134135
```
135136

@@ -141,7 +142,7 @@ Register `benchmarks` source set:
141142

142143
```groovy
143144
benchmarks {
144-
configurations {
145+
targets {
145146
register("benchmarks")
146147
}
147148
}

examples/kotlin-multiplatform/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,17 @@ benchmark {
9999
configurations {
100100
main { // --> jvmBenchmark/jsBenchmark + benchmark
101101
iterations = 5 // number of iterations
102-
iterationTime = 300 // time in ms per iteration
102+
iterationTime = 300
103+
iterationTimeUnit = "ms"
103104
}
104105

105106
big { // --> jvmBigBenchmark + bigBenchmark(jvm+js+native)
106107
param("collectionSize", "1000000")
107108
}
108109

109110
fast { // --> jvmFastBenchmark
110-
include(".*Common.*")
111-
exclude(".*long.*")
111+
include("Common")
112+
exclude("long")
112113
param("collectionSize", 10)
113114
param("repeats", 1000)
114115
iterations = 1

examples/kotlin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ sourceSets {
2121
// You can add "+ sourceSets.test.output" to include test output as well
2222
dependencies {
2323
implementation(project(":runtime"))
24-
benchmarksCompile sourceSets.main.output + sourceSets.main.compileClasspath
24+
benchmarksCompile sourceSets.main.output + sourceSets.main.runtimeClasspath
2525
}
2626

2727
// Configure benchmark

plugin/main/src/org/jetbrains/gradle/benchmarks/BenchmarkConfiguration.kt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ open class BenchmarkConfiguration(val extension: BenchmarksExtension, val name:
77
var iterations: Int? = null
88
var iterationTime: Long? = null
99
var iterationTimeUnit: String? = null
10+
var mode: String? = null
11+
var outputTimeUnit: String? = null
12+
1013
var includes: MutableList<String> = mutableListOf()
1114
var excludes: MutableList<String> = mutableListOf()
1215
var params: MutableMap<String, Any?> = mutableMapOf()
@@ -23,23 +26,6 @@ open class BenchmarkConfiguration(val extension: BenchmarksExtension, val name:
2326
params[name] = value
2427
}
2528

26-
// TODO: this is error prone. User should use the mutable variables above. Plugin code should use these methods
27-
// Basically, we want external properties, such as `-P` to override what's in build script
28-
// We also want to use defaults if per configuration setting is missing
29-
fun iterations(): Int {
30-
val externalSetting = extension.project.findProperty("benchmarks_iterations") as? String
31-
if (externalSetting != null)
32-
return externalSetting.toInt()
33-
return iterations ?: extension.defaults.iterations
34-
}
35-
36-
fun iterationTime(): Long {
37-
val externalSetting = extension.project.findProperty("benchmarks_iterationTime") as? String
38-
if (externalSetting != null)
39-
return externalSetting.toLong()
40-
return iterationTime ?: extension.defaults.iterationTime
41-
}
42-
4329
fun capitalizedName() = if (name == "main") "" else name.capitalize()
4430
fun prefixName(suffix: String) = if (name == "main") suffix else name + suffix.capitalize()
4531
}

plugin/main/src/org/jetbrains/gradle/benchmarks/BenchmarksExtension.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,16 @@ open class BenchmarksExtension(val project: Project) {
1717

1818
val version = BenchmarksPlugin.PLUGIN_VERSION
1919

20-
val defaults = BenchmarkConfigurationDefaults()
21-
22-
fun defaults(configure: Action<BenchmarkConfigurationDefaults>) {
23-
configure.execute(defaults)
24-
}
25-
26-
fun defaults(configure: Closure<BenchmarkConfigurationDefaults>) {
27-
ConfigureUtil.configureSelf(configure, defaults)
28-
}
29-
3020
fun configurations(configureClosure: Closure<NamedDomainObjectContainer<BenchmarkConfiguration>>): NamedDomainObjectContainer<BenchmarkConfiguration> {
3121
return configurations.configure(configureClosure)
3222
}
3323

3424
val configurations: NamedDomainObjectContainer<BenchmarkConfiguration> = run {
35-
project.container(BenchmarkConfiguration::class.java) { name ->
25+
val container = project.container(BenchmarkConfiguration::class.java) { name ->
3626
BenchmarkConfiguration(this, name)
3727
}
28+
container.register("main")
29+
container
3830
}
3931

4032
fun targets(configureClosure: Closure<NamedDomainObjectContainer<BenchmarkTarget>>): NamedDomainObjectContainer<BenchmarkTarget> {

plugin/main/src/org/jetbrains/gradle/benchmarks/JsNodeTasks.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ fun Project.createJsBenchmarkExecTask(
5353

5454
arguments("-n", target.name)
5555
arguments("-r", reportFile.toString())
56-
arguments("-i", config.iterations().toString())
57-
arguments("-it", config.iterationTime().toString())
58-
arguments("-itu", config.iterationTimeUnit.toString())
56+
config.iterations?.let { arguments("-i", it.toString()) }
57+
config.iterationTime?.let { arguments("-it", it.toString()) }
58+
config.iterationTimeUnit?.let { arguments("-itu", it) }
59+
config.outputTimeUnit?.let { arguments("-otu", it) }
60+
config.mode?.let { arguments("-m", it) }
5961

6062
config.includes.forEach {
6163
arguments("-I", it)

plugin/main/src/org/jetbrains/gradle/benchmarks/JvmTasks.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ fun Project.createJvmBenchmarkExecTask(
110110

111111
args("-n", target.name)
112112
args("-r", reportFile.toString())
113-
args("-i", config.iterations().toString())
114-
args("-it", config.iterationTime().toString())
115-
args("-itu", config.iterationTimeUnit.toString())
113+
config.iterations?.let { args("-i", it.toString()) }
114+
config.iterationTime?.let { args("-it", it.toString()) }
115+
config.iterationTimeUnit?.let { args("-itu", it) }
116+
config.outputTimeUnit?.let { args("-otu", it) }
117+
config.mode?.let { args("-m", it) }
116118

117119
config.includes.forEach {
118120
args("-I", it)

plugin/main/src/org/jetbrains/gradle/benchmarks/NativeMultiplatformTasks.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ fun Project.createNativeBenchmarkExecTask(
114114

115115
args("-n", target.name)
116116
args("-r", reportFile.toString())
117-
args("-i", config.iterations().toString())
118-
args("-it", config.iterationTime().toString())
119-
args("-itu", config.iterationTimeUnit.toString())
117+
config.iterations?.let { args("-i", it.toString()) }
118+
config.iterationTime?.let { args("-it", it.toString()) }
119+
config.iterationTimeUnit?.let { args("-itu", it) }
120+
config.outputTimeUnit?.let { args("-otu", it) }
121+
config.mode?.let { args("-m", it) }
120122

121123
config.includes.forEach {
122124
args("-I", it)

runtime/commonMain/src/org/jetbrains/gradle/benchmarks/SuiteExecutor.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ abstract class SuiteExecutor(val executionName: String, arguments: Array<out Str
1818
fun run() {
1919
//println(config.toString())
2020
reporter.startSuite(executionName)
21-
val include = config.include.map { Regex(it) }
21+
val include = if (config.include.isEmpty())
22+
listOf(Regex(".*"))
23+
else
24+
config.include.map { Regex(it) }
2225
val exclude = config.exclude.map { Regex(it) }
2326

2427
@Suppress("UNCHECKED_CAST")
2528
val benchmarks = suites.flatMap { suite ->
2629
suite.benchmarks
2730
.filter { benchmark ->
2831
val fullName = suite.name + "." + benchmark.name
29-
include.any { it.matches(fullName) } && exclude.none { it.matches(fullName) }
32+
include.any { it.containsMatchIn(fullName) } && exclude.none { it.containsMatchIn(fullName) }
3033
} as List<BenchmarkDescriptor<Any?>>
3134
}
3235

0 commit comments

Comments
 (0)