@@ -72,7 +72,8 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
72
72
reporter.startBenchmark(executionName, id)
73
73
val samples = run (benchmark, benchmarkRun)
74
74
if (samples != null ) {
75
- saveBenchmarkResults(benchmark, benchmarkRun, samples, resultsFile)
75
+ writeFile(resultsFile, samples.joinToString())
76
+ saveBenchmarkResults(benchmark, benchmarkRun, samples)
76
77
}
77
78
}
78
79
@@ -107,16 +108,17 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
107
108
} finally {
108
109
benchmark.suite.teardown(instance)
109
110
}
110
- exception?. let {
111
+ if ( exception != null ) {
111
112
val error = exception.toString()
112
113
val stacktrace = exception.stacktrace()
113
114
reporter.endBenchmarkException(executionName, id, error, stacktrace)
114
115
return null
115
- } ? : return samples
116
+ }
117
+ return samples
116
118
}
117
119
118
120
private fun saveBenchmarkResults (benchmark : BenchmarkDescriptor <Any ?>, benchmarkRun : BenchmarkRun ,
119
- samples : DoubleArray , fileName : String? = null ) {
121
+ samples : DoubleArray ) {
120
122
val id = id(benchmark.name, benchmarkRun.parameters)
121
123
val result = ReportBenchmarksStatistics .createResult(benchmark, benchmarkRun.parameters, benchmarkRun.config, samples)
122
124
val message = with (result) {
@@ -136,15 +138,20 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
136
138
message
137
139
)
138
140
result(result)
139
- fileName?.let { writeFile(it, JsonBenchmarkReportFormatter .format(result)) }
140
141
}
141
142
142
- fun storeResults (benchmarks : List <BenchmarkDescriptor <Any ?>>) {
143
- val (configFileName, fileName) = additionalArguments
144
- val benchmarkRun = configFileName.parseBenchmarkConfig()
145
- val benchmark = benchmarks.getBenchmark(benchmarkRun.benchmarkName)
146
- val samples = fileName.readFile().split(" , " ).map { it.toDouble() }.toDoubleArray()
147
- saveBenchmarkResults(benchmark, benchmarkRun, samples, fileName)
143
+ private fun storeResults (benchmarks : List <BenchmarkDescriptor <Any ?>>, complete : () -> Unit ) {
144
+ val (_, resultsFileName) = additionalArguments
145
+ resultsFileName.readFile().split(" \n " ).filter { it.isNotEmpty() }.forEach {
146
+ val (configFileName, samplesList) = it.split(" : " )
147
+ val samples = samplesList.split(" , " ).map { it.toDouble() }.toDoubleArray()
148
+ val benchmarkRun = configFileName.parseBenchmarkConfig()
149
+ val benchmark = benchmarks.getBenchmark(benchmarkRun.benchmarkName)
150
+ val result = ReportBenchmarksStatistics .createResult(benchmark, benchmarkRun.parameters,
151
+ benchmarkRun.config, samples)
152
+ result(result)
153
+ }
154
+ complete()
148
155
}
149
156
150
157
override fun run (
@@ -154,18 +161,24 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
154
161
start : () -> Unit ,
155
162
complete : () -> Unit
156
163
) {
157
- when (additionalArguments.size) {
158
- 1 -> complete()
159
- 2 -> when (additionalArguments.first()) {
160
- " --list" -> outputBenchmarks(runnerConfiguration, benchmarks, start)
161
- else -> storeResults(benchmarks)
162
- }
163
- 3 -> when (additionalArguments.first()) {
164
- " --internal" -> runBenchmark(benchmarks)
165
- else -> runBenchmarkIteration(benchmarks)
166
- }
167
- 4 -> runBenchmarkWarmup(benchmarks)
164
+ val knownActions = mapOf (
165
+ " --list" to 2 ,
166
+ " --store-results" to 2 ,
167
+ " --internal" to 3 ,
168
+ " --iteration" to 4 ,
169
+ " --warmup" to 5
170
+ )
168
171
172
+ val action = additionalArguments.first()
173
+ if (action !in knownActions.keys)
174
+ throw NoSuchElementException (" Action $action isn't found in the list of possible actions ${knownActions.keys} ." )
175
+ require(knownActions[action] == additionalArguments.size)
176
+ when (action) {
177
+ " --list" -> outputBenchmarks(runnerConfiguration, benchmarks, start)
178
+ " --store-results" -> storeResults(benchmarks, complete)
179
+ " --internal" -> runBenchmark(benchmarks)
180
+ " --iteration" -> runBenchmarkIteration(benchmarks)
181
+ " --warmup" -> runBenchmarkWarmup(benchmarks)
169
182
}
170
183
}
171
184
0 commit comments