Skip to content

Commit dd8962d

Browse files
author
Abduqodiri Qurbonzoda
committed
[K/N] Fix crash that occurs when no benchmarks where run
1 parent d6040e6 commit dd8962d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal object TextBenchmarkReportFormatter : BenchmarkReportFormatter() {
2121

2222
override fun format(results: Collection<ReportBenchmarkResult>): String {
2323
fun columnLength(column: String, selector: (ReportBenchmarkResult) -> String): Int =
24-
max(column.length, results.maxOf { selector(it).length })
24+
max(column.length, results.maxOfOrNull { selector(it).length } ?: 0)
2525

2626
val shortNames = denseBenchmarkNames(results.map { it.benchmark.name })
2727
val nameLength = columnLength("Benchmark") { shortNames[it.benchmark.name]!! }

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class NativeExecutor(
172172
}
173173

174174
private fun storeResults(benchmarks: List<BenchmarkDescriptor<Any?>>, complete: () -> Unit) {
175-
additionalArguments[0].readFile().lines().forEach {
175+
val resultsContent = additionalArguments[0].readFile()
176+
resultsContent.takeIf(String::isNotEmpty)?.lines()?.forEach {
176177
val (configFileName, samplesList) = it.split(": ")
177178
val samples = samplesList.split(", ").map { it.toDouble() }.toDoubleArray()
178179
val benchmarkRun = configFileName.parseBenchmarkConfig()

0 commit comments

Comments
 (0)