Skip to content

Commit 08a9894

Browse files
Abduqodiri Qurbonzodailya-g
andcommitted
Rename nativeGCCollectMode -> nativeGCAfterIteration, auto -> false, iteration -> true
Co-authored-by: ilya-g <[email protected]>
1 parent e31ecc8 commit 08a9894

File tree

7 files changed

+15
-31
lines changed

7 files changed

+15
-31
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ Available configuration options:
151151
* `nativeFork`
152152
- "perBenchmark" (default) – executes all iterations of a benchmark in the same process (one binary execution)
153153
- "perIteration" – executes each iteration of a benchmark in a separate process, measures in cold Kotlin/Native runtime environment
154-
* `nativeGCCollectMode`
155-
- "auto" (default) – collects garbage at the moments choosen by K/N compiler, time for each iteration can be very
156-
different because of unpredictable GC calls.
157-
- "iteration" – collects garbage after each measuring iteration
154+
* `nativeGCAfterIteration` – when set to `true`, additionally collects garbage after each measuring iteration (default is `false`).
158155
* `include("…")` – regular expression to include benchmarks with fully qualified names matching it, as a substring
159156
* `exclude("…")` – regular expression to exclude benchmarks with fully qualified names matching it, as a substring
160157
* `param("name", "value1", "value2")` – specify a parameter for a public mutable property `name` annotated with `@Param`

examples/kotlin-multiplatform/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ benchmark {
8080
iterationTimeUnit = "ms" // time in ms per iteration
8181
advanced("forks", 1)
8282
advanced("nativeFork", "perIteration")
83-
advanced("nativeGCCollectMode", "iteration")
83+
advanced("nativeGCAfterIteration", "true")
8484
}
8585

8686
csv {

runtime/commonMain/src/kotlinx/benchmark/BenchmarkReportFormatter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private object JsonBenchmarkReportFormatter : BenchmarkReportFormatter() {
175175
${result.params.entries.joinToString(separator = ",\n ") { "\"${it.key}\" : \"${it.value}\"" }}
176176
},
177177
"nativeFork" : "${result.config.nativeFork.toText()}",
178-
"nativeGCCollectMode" : "${result.config.nativeGCCollectMode.toText()}",
178+
"nativeGCAfterIteration" : "${result.config.nativeGCAfterIteration}",
179179
"primaryMetric" : {
180180
"score": ${result.score},
181181
"scoreError": ${result.error},

runtime/commonMain/src/kotlinx/benchmark/CommonBenchmarkAnnotations.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ enum class NativeFork {
2828
PerBenchmark, PerIteration
2929
}
3030

31-
enum class NativeGCCollectMode {
32-
Auto, Iteration
33-
}
34-
3531
@Target(AnnotationTarget.CLASS)
3632
expect annotation class OutputTimeUnit(val value: BenchmarkTimeUnit)
3733

@@ -71,13 +67,6 @@ fun NativeFork.toText() = when (this) {
7167
else -> throw UnsupportedOperationException("$this is not supported")
7268
}
7369

74-
@Suppress("REDUNDANT_ELSE_IN_WHEN")
75-
fun NativeGCCollectMode.toText() = when (this) {
76-
NativeGCCollectMode.Auto -> "auto"
77-
NativeGCCollectMode.Iteration -> "iteration"
78-
else -> throw UnsupportedOperationException("$this is not supported")
79-
}
80-
8170
@Suppress("REDUNDANT_ELSE_IN_WHEN")
8271
fun BenchmarkTimeUnit.toMultiplier() = when (this) {
8372
BenchmarkTimeUnit.NANOSECONDS -> 1

runtime/commonMain/src/kotlinx/benchmark/ExecutorConfiguration.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class BenchmarkConfiguration private constructor(
88
val outputTimeUnit: BenchmarkTimeUnit,
99
val mode: Mode,
1010
val nativeFork: NativeFork,
11-
val nativeGCCollectMode: NativeGCCollectMode) {
11+
val nativeGCAfterIteration: Boolean) {
1212

1313
constructor(runner: RunnerConfiguration, suite: SuiteDescriptor<*>) : this(
1414
runner.iterations ?: suite.iterations,
@@ -18,14 +18,14 @@ class BenchmarkConfiguration private constructor(
1818
runner.outputTimeUnit ?: suite.outputTimeUnit,
1919
runner.mode ?: suite.mode,
2020
runner.nativeFork ?: NativeFork.PerBenchmark,
21-
runner.nativeGCCollectMode ?: NativeGCCollectMode.Auto
21+
runner.nativeGCAfterIteration ?: false
2222
)
2323

2424
override fun toString() =
2525
"iterations=$iterations, warmups=$warmups, iterationTime=$iterationTime, " +
2626
"iterationTimeUnit=${iterationTimeUnit.toText()}, outputTimeUnit=${outputTimeUnit.toText()}, " +
2727
"mode=${mode.toText()}, nativeFork=${nativeFork.toText()}, " +
28-
"nativeGCCollectMode=${nativeGCCollectMode.toText()}"
28+
"nativeGCAfterIteration=$nativeGCAfterIteration"
2929

3030
companion object {
3131
fun parse(description: String): BenchmarkConfiguration {
@@ -42,7 +42,7 @@ class BenchmarkConfiguration private constructor(
4242
parseTimeUnit(getParameterValue("outputTimeUnit")),
4343
getParameterValue("mode").toMode(),
4444
NativeFork.valueOf(getParameterValue("nativeFork").replaceFirstChar { it.uppercaseChar() }),
45-
NativeGCCollectMode.valueOf(getParameterValue("nativeGCCollectMode").replaceFirstChar { it.uppercaseChar() })
45+
getParameterValue("nativeGCAfterIteration").toBooleanStrict()
4646
)
4747
}
4848
}

runtime/commonMain/src/kotlinx/benchmark/RunnerConfiguration.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ class RunnerConfiguration(config: String) {
7272
"nativeFork"
7373
) { NativeFork.valueOf(it.replaceFirstChar { firstChar -> firstChar.uppercaseChar() }) }
7474

75-
val nativeGCCollectMode = singleValueOrNull(
76-
"nativeGCCollectMode"
77-
) { NativeGCCollectMode.valueOf(it.replaceFirstChar { firstChar -> firstChar.uppercaseChar() }) }
75+
val nativeGCAfterIteration = singleValueOrNull("nativeGCAfterIteration") { it.toBooleanStrict() }
7876

7977
override fun toString(): String {
8078
return """$name -> $reportFile ($traceFormat, $reportFormat)
@@ -88,7 +86,7 @@ iterationTimeUnit: $iterationTimeUnit
8886
outputTimeUnit: $outputTimeUnit
8987
mode: $mode
9088
nativeFork: $nativeFork
91-
nativeGCCollectMode: $nativeGCCollectMode
89+
nativeGCAfterIteration: $nativeGCAfterIteration
9290
"""
9391
}
9492
}

runtime/nativeMain/src/kotlinx/benchmark/native/NativeExecutor.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class NativeExecutor(
123123
// Execute warmup
124124
val cycles = cyclesPerIteration ?: warmup(suite.name, benchmarkRun.config, instance, benchmark)
125125
DoubleArray(iterations) { iteration ->
126-
val nanosecondsPerOperation = measure(instance, benchmark, cycles, benchmarkRun.config.nativeGCCollectMode)
126+
val nanosecondsPerOperation = measure(instance, benchmark, cycles, benchmarkRun.config.nativeGCAfterIteration)
127127
val text = nanosecondsPerOperation.nanosToText(benchmarkRun.config.mode, benchmarkRun.config.outputTimeUnit)
128128
val iterationNumber = currentIteration ?: iteration
129129
reporter.output(
@@ -210,18 +210,18 @@ class NativeExecutor(
210210
instance: T,
211211
benchmark: BenchmarkDescriptor<T>,
212212
cycles: Int,
213-
nativeGCCollectMode: NativeGCCollectMode
213+
nativeGCAfterIteration: Boolean
214214
): Double {
215215
val executeFunction = benchmark.function
216216
var counter = cycles
217-
if (nativeGCCollectMode == NativeGCCollectMode.Iteration)
217+
if (nativeGCAfterIteration)
218218
GC.collect()
219219
val startTime = getTimeNanos()
220220
while (counter-- > 0) {
221221
@Suppress("UNUSED_VARIABLE")
222222
val result = instance.executeFunction() // ignore result for now, but might need to consume it somehow
223223
}
224-
if (nativeGCCollectMode == NativeGCCollectMode.Iteration)
224+
if (nativeGCAfterIteration)
225225
GC.collect()
226226
val endTime = getTimeNanos()
227227
val time = endTime - startTime
@@ -246,7 +246,7 @@ class NativeExecutor(
246246
val benchmarkNanos = config.iterationTime * config.iterationTimeUnit.toMultiplier()
247247
val executeFunction = benchmark.function
248248

249-
if (config.nativeGCCollectMode == NativeGCCollectMode.Iteration)
249+
if (config.nativeGCAfterIteration)
250250
GC.collect()
251251
val startTime = getTimeNanos()
252252
var endTime = startTime
@@ -256,7 +256,7 @@ class NativeExecutor(
256256
endTime = getTimeNanos()
257257
iterations++
258258
}
259-
if (config.nativeGCCollectMode == NativeGCCollectMode.Iteration)
259+
if (config.nativeGCAfterIteration)
260260
GC.collect()
261261

262262
val time = endTime - startTime

0 commit comments

Comments
 (0)