Skip to content

Commit 7ae5d77

Browse files
committed
[benchmark] Report totals as a sentence
Clean up after removing bogus agregate statistics from last line of the log. It makes more sense to report the total number of executed benchmarks as a sentence that trying to fit into the format of preceding table. Added test assertion that `run_benchmarks` return csv formatted log, as it is used to write the log into file in `log_results`.
1 parent ef1461c commit 7ae5d77

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -442,24 +442,17 @@ def run_benchmarks(driver):
442442
else:
443443
print(','.join(test_output))
444444
output.append(test_output)
445-
if not output:
446-
return
447-
formatted_output = '\n'.join([','.join(l) for l in output])
448-
totals = ['Totals', str(len(driver.tests))]
449-
totals_output = '\n\n' + ','.join(totals)
450-
if log:
451-
print(line_format.format(*([''] + totals + ([''] * 6))))
452-
else:
453-
print(totals_output[1:])
454-
formatted_output += totals_output
455-
return formatted_output
445+
446+
print('\nTotal performance tests executed: {0}'.format(len(driver.tests)))
447+
csv_log = '\n'.join([','.join(l) for l in output]) + '\n'
448+
return csv_log
456449

457450

458451
def run(args):
459452
driver = BenchmarkDriver(args)
460-
output = run_benchmarks(driver)
461-
if args.output_dir:
462-
driver.log_results(output)
453+
csv_log = run_benchmarks(driver)
454+
if args.output_dir and csv_log:
455+
driver.log_results(csv_log)
463456
return 0
464457

465458

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,28 +295,31 @@ def mock_run(test):
295295
driver.run_independent_samples = mock_run
296296

297297
with captured_output() as (out, _):
298-
formatted_output = run_benchmarks(driver)
298+
log = run_benchmarks(driver)
299299

300+
csv_log = '3,b1,1,123,123,123,0,123,888\n'
301+
self.assertEquals(log, csv_log)
300302
self.assertEquals(
301303
out.getvalue(),
302304
'#,TEST,SAMPLES,MIN(μs),MAX(μs),MEAN(μs),SD(μs),MEDIAN(μs),' +
303305
'MAX_RSS(B)\n' +
304-
'3,b1,1,123,123,123,0,123,888\n\nTotals,1\n')
305-
self.assertEquals(formatted_output,
306-
'3,b1,1,123,123,123,0,123,888\n' +
307-
'\nTotals,1')
306+
csv_log +
307+
'\n' +
308+
'Total performance tests executed: 1\n')
308309

309310
driver.args.output_dir = 'logs/'
310311
with captured_output() as (out, _):
311-
run_benchmarks(driver)
312+
log = run_benchmarks(driver)
313+
314+
self.assertEquals(log, csv_log)
312315
self.assertEquals(
313316
out.getvalue(),
314317
' # TEST SAMPLES MIN(μs) MAX(μs)' +
315318
' MEAN(μs) SD(μs) MEDIAN(μs) MAX_RSS(B)\n' +
316319
' 3 b1 1 123 123' +
317320
' 123 0 123 888\n' +
318-
' Totals 1 ' +
319-
' \n')
321+
'\n' +
322+
'Total performance tests executed: 1\n')
320323

321324
def test_log_results(self):
322325
"""Create log directory if it doesn't exist and write the log file."""

benchmark/scripts/test_compare_perf_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_parse_results_csv(self):
328328
log = """#,TEST,SAMPLES,MIN(us),MAX(us),MEAN(us),SD(us),MEDIAN(us)
329329
34,BitCount,20,3,4,4,0,4
330330
331-
Totals,269
331+
Total performance tests executed: 1
332332
"""
333333
parser = LogParser()
334334
results = parser.parse_results(log.splitlines())
@@ -347,7 +347,9 @@ def test_parse_results_formatted_text(self):
347347
log = ("""
348348
# TEST SAMPLES MIN(μs) MAX(μs) MEAN(μs) SD(μs) MEDIAN(μs) MAX_RSS(B)
349349
3 Array2D 20 2060 2188 2099 0 2099 20915200
350-
Totals 281""")
350+
351+
Total performance tests executed: 1
352+
""")
351353
parser = LogParser()
352354
results = parser.parse_results(log.splitlines()[1:]) # without 1st \n
353355
self.assertTrue(isinstance(results[0], PerformanceTestResult))

benchmark/utils/DriverUtils.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ func runBenchmarks(_ c: TestConfig) {
443443
report(index, test, results:runBench(test, c))
444444
}
445445

446-
print("")
447-
print("Totals\(c.delim)\(testCount)")
446+
print("\nTotal performance tests executed: \(testCount)")
448447
}
449448

450449
public func main() {

0 commit comments

Comments
 (0)