Skip to content

Commit e007219

Browse files
committed
Review fixes + refinements
1 parent 72d00e9 commit e007219

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

benchmarks/multiplatform/benchmarks/src/commonMain/kotlin/BenchmarksSave.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ import kotlinx.io.readByteArray
2020
// port for the benchmarks save server
2121
val BENCHMARK_SERVER_PORT = 8090
2222

23+
private val BENCHMARKS_SAVE_DIR = "build/benchmarks"
24+
private fun pathToCsv(name: String) = Path("$BENCHMARKS_SAVE_DIR/$name.csv")
25+
private fun pathToJson(name: String) = Path("$BENCHMARKS_SAVE_DIR/json-reports/$name.json")
26+
27+
internal fun saveJson(benchmarkName: String, jsonString: String) {
28+
val jsonPath = pathToJson(benchmarkName)
29+
SystemFileSystem.createDirectories(jsonPath.parent!!)
30+
SystemFileSystem.sink(jsonPath).writeText(jsonString)
31+
println("JSON results saved to ${SystemFileSystem.resolve(jsonPath)}")
32+
}
33+
2334
fun saveBenchmarkStatsOnDisk(name: String, stats: BenchmarkStats) {
2435
try {
2536
if (Config.saveStatsToCSV) {
26-
val path = Path("build/benchmarks/$name.csv")
37+
val path = pathToCsv(name)
2738

2839
val keyToValue = mutableMapOf<String, String>()
2940
keyToValue.put("Date", currentFormattedDate)
@@ -43,12 +54,7 @@ fun saveBenchmarkStatsOnDisk(name: String, stats: BenchmarkStats) {
4354
println("CSV results saved to ${SystemFileSystem.resolve(path)}")
4455
println()
4556
} else if (Config.saveStatsToJSON) {
46-
val jsonString = stats.toJsonString()
47-
val jsonPath = Path("build/benchmarks/json-reports/$name.json")
48-
49-
SystemFileSystem.createDirectories(jsonPath.parent!!)
50-
SystemFileSystem.sink(jsonPath).writeText(jsonString)
51-
println("JSON results saved to ${SystemFileSystem.resolve(jsonPath)}")
57+
saveJson(name, stats.toJsonString())
5258
println()
5359
}
5460
} catch (_: IOException) {

benchmarks/multiplatform/benchmarks/src/desktopMain/kotlin/BenchmarksSaveServer.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object BenchmarksSaveServer {
4949
allowMethod(HttpMethod.Get)
5050
allowMethod(HttpMethod.Post)
5151
allowHeader(HttpHeaders.ContentType)
52-
allowHost("localhost:8080")
52+
anyHost()
5353
}
5454
routing {
5555
post("/benchmark") {
@@ -64,10 +64,7 @@ object BenchmarksSaveServer {
6464

6565
withContext(Dispatchers.IO) {
6666
if (Config.saveStatsToJSON) {
67-
val jsonPath = Path("build/benchmarks/json-reports/${result.name}.json")
68-
SystemFileSystem.createDirectories(jsonPath.parent!!)
69-
SystemFileSystem.sink(jsonPath).writeText(result.stats)
70-
println("JSON results saved to ${SystemFileSystem.resolve(jsonPath)}")
67+
saveJson(result.name, result.stats)
7168
}
7269

7370
if (Config.saveStatsToCSV) {

0 commit comments

Comments
 (0)