From a6fd49835aa893f1401e7a63c5fd6689cf5d3eaa Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Fri, 15 Oct 2021 19:12:10 +0300 Subject: [PATCH] [K/N] Fix crash that occurs when no benchmarks where run --- .../src/kotlinx/benchmark/BenchmarkReportFormatter.kt | 2 +- .../nativeMain/src/kotlinx/benchmark/native/NativeExecutor.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/commonMain/src/kotlinx/benchmark/BenchmarkReportFormatter.kt b/runtime/commonMain/src/kotlinx/benchmark/BenchmarkReportFormatter.kt index 4f345a7c..dddf9dcd 100644 --- a/runtime/commonMain/src/kotlinx/benchmark/BenchmarkReportFormatter.kt +++ b/runtime/commonMain/src/kotlinx/benchmark/BenchmarkReportFormatter.kt @@ -21,7 +21,7 @@ internal object TextBenchmarkReportFormatter : BenchmarkReportFormatter() { override fun format(results: Collection): String { fun columnLength(column: String, selector: (ReportBenchmarkResult) -> String): Int = - max(column.length, results.maxOf { selector(it).length }) + max(column.length, results.maxOfOrNull { selector(it).length } ?: 0) val shortNames = denseBenchmarkNames(results.map { it.benchmark.name }) val nameLength = columnLength("Benchmark") { shortNames[it.benchmark.name]!! } diff --git a/runtime/nativeMain/src/kotlinx/benchmark/native/NativeExecutor.kt b/runtime/nativeMain/src/kotlinx/benchmark/native/NativeExecutor.kt index e6f701a9..6e804b9a 100644 --- a/runtime/nativeMain/src/kotlinx/benchmark/native/NativeExecutor.kt +++ b/runtime/nativeMain/src/kotlinx/benchmark/native/NativeExecutor.kt @@ -172,7 +172,8 @@ class NativeExecutor( } private fun storeResults(benchmarks: List>, complete: () -> Unit) { - additionalArguments[0].readFile().lines().forEach { + val resultsContent = additionalArguments[0].readFile() + resultsContent.takeIf(String::isNotEmpty)?.lines()?.forEach { val (configFileName, samplesList) = it.split(": ") val samples = samplesList.split(", ").map { it.toDouble() }.toDoubleArray() val benchmarkRun = configFileName.parseBenchmarkConfig()