@@ -34,10 +34,10 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
34
34
? : throw NoSuchElementException (" Benchmark $name wasn't found." )
35
35
36
36
private fun runBenchmarkIteration (benchmarks : List <BenchmarkDescriptor <Any ?>>) {
37
- val (configFileName, iteration, resultsFile) = additionalArguments
37
+ val (_, configFileName, iteration, cycles , resultsFile) = additionalArguments
38
38
val benchmarkRun = configFileName.parseBenchmarkConfig()
39
39
val benchmark = benchmarks.getBenchmark(benchmarkRun.benchmarkName)
40
- val samples = run (benchmark, benchmarkRun, iteration.toInt())
40
+ val samples = run (benchmark, benchmarkRun, iteration.toInt(), cycles.toInt() )
41
41
writeFile(resultsFile, samples?.let { it[0 ].toString() } ? : " null" )
42
42
}
43
43
@@ -46,14 +46,18 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
46
46
val benchmarkRun = configFileName.parseBenchmarkConfig()
47
47
val benchmark = benchmarks.getBenchmark(benchmarkRun.benchmarkName)
48
48
val id = id(benchmark.name, benchmarkRun.parameters)
49
- if (iteration.toInt() == 0 ) {
50
- reporter.startBenchmark(executionName, id)
51
- }
49
+
52
50
val instance = benchmark.suite.factory() // TODO: should we create instance per bench or per suite?
53
51
benchmark.suite.parametrize(instance, benchmarkRun.parameters)
54
52
benchmark.suite.setup(instance)
53
+
54
+ if (iteration.toInt() == 0 ) {
55
+ reporter.startBenchmark(executionName, id)
56
+ }
55
57
try {
56
- warmup(benchmark.suite.name, benchmarkRun.config, benchmark.suite.factory(), benchmark, iteration.toInt())
58
+ val iterations = warmup(benchmark.suite.name, benchmarkRun.config, instance,
59
+ benchmark, iteration.toInt())
60
+ writeFile(resultsFile, iterations.toString())
57
61
} catch (e: Throwable ) {
58
62
val error = e.toString()
59
63
val stacktrace = e.stacktrace()
@@ -77,8 +81,16 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
77
81
}
78
82
}
79
83
84
+ private fun endExternalBenchmarksRun (benchmarks : List <BenchmarkDescriptor <Any ?>>) {
85
+ val (_, configFileName, samplesFile) = additionalArguments
86
+ val samples = samplesFile.readFile().split(" , " ).map { it.toDouble() }.toDoubleArray()
87
+ val benchmarkRun = configFileName.parseBenchmarkConfig()
88
+ val benchmark = benchmarks.getBenchmark(benchmarkRun.benchmarkName)
89
+ saveBenchmarkResults(benchmark, benchmarkRun, samples)
90
+ }
91
+
80
92
fun run (benchmark : BenchmarkDescriptor <Any ?>, benchmarkRun : BenchmarkRun ,
81
- externalIterationNumber : Int? = null): DoubleArray? {
93
+ externalIterationNumber : Int? = null, externalCyclesNumber : Int? = null ): DoubleArray? {
82
94
val id = id(benchmark.name, benchmarkRun.parameters)
83
95
val suite = benchmark.suite
84
96
@@ -90,7 +102,7 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
90
102
val iterations = if (benchmarkRun.config.nativeIterationMode == NativeIterationMode .External ) 1 else benchmarkRun.config.iterations
91
103
val samples = try {
92
104
// Execute warmup
93
- val cycles = warmup(suite.name, benchmarkRun.config, instance, benchmark)
105
+ val cycles = externalCyclesNumber ? : warmup(suite.name, benchmarkRun.config, instance, benchmark)
94
106
DoubleArray (iterations) { iteration ->
95
107
val nanosecondsPerOperation = measure(instance, benchmark, cycles)
96
108
val text = nanosecondsPerOperation.nanosToText(benchmarkRun.config.mode, benchmarkRun.config.outputTimeUnit)
@@ -164,9 +176,10 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
164
176
val knownActions = mapOf (
165
177
" --list" to 2 ,
166
178
" --store-results" to 2 ,
179
+ " --end-run" to 3 ,
167
180
" --internal" to 3 ,
168
- " --iteration" to 4 ,
169
- " --warmup" to 5
181
+ " --iteration" to 5 ,
182
+ " --warmup" to 4
170
183
)
171
184
172
185
val action = additionalArguments.first()
@@ -179,6 +192,7 @@ class NativeExecutor(name: String, args: Array<out String>) : SuiteExecutor(name
179
192
" --internal" -> runBenchmark(benchmarks)
180
193
" --iteration" -> runBenchmarkIteration(benchmarks)
181
194
" --warmup" -> runBenchmarkWarmup(benchmarks)
195
+ " --end-run" -> endExternalBenchmarksRun(benchmarks)
182
196
}
183
197
}
184
198
0 commit comments