@@ -20,10 +20,21 @@ import kotlinx.io.readByteArray
2020// port for the benchmarks save server
2121val 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+
2334fun 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 ) {
0 commit comments