Skip to content

Commit 6bddcbe

Browse files
committed
[benchmark] Refactor run_benchmarks log format
1 parent 7ae5d77 commit 6bddcbe

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -418,33 +418,32 @@ def run_benchmarks(driver):
418418
"""
419419
# Set a constant hash seed. Some tests are currently sensitive to
420420
# fluctuations in the number of hash collisions.
421-
#
422-
# FIXME: This should only be set in the environment of the child process
423-
# that runs the tests.
424421
os.environ["SWIFT_DETERMINISTIC_HASHING"] = "1"
425422

426-
log = driver.args.output_dir
427-
output = []
428-
headings = ['#', 'TEST', 'SAMPLES', 'MIN(μs)', 'MAX(μs)', 'MEAN(μs)',
429-
'SD(μs)', 'MEDIAN(μs)', 'MAX_RSS(B)']
430423
line_format = '{:>3} {:<25} {:>7} {:>7} {:>7} {:>8} {:>6} {:>10} {:>10}'
431-
if log:
432-
print(line_format.format(*headings))
433-
else:
434-
print(','.join(headings))
424+
format = (
425+
(lambda values: ','.join(values)) # CSV
426+
if (driver.args.output_dir is None) else
427+
(lambda values: line_format.format(*values))) # justified columns
428+
429+
def console_log(values):
430+
print(format(values))
431+
432+
console_log(['#', 'TEST', 'SAMPLES', 'MIN(μs)', 'MAX(μs)', # header
433+
'MEAN(μs)', 'SD(μs)', 'MEDIAN(μs)', 'MAX_RSS(B)'])
434+
435+
def result_values(r):
436+
return map(str, [r.test_num, r.name, r.num_samples, r.min, r.max,
437+
int(r.mean), int(r.sd), r.median, r.max_rss])
438+
439+
results = []
435440
for test in driver.tests:
436-
r = driver.run_independent_samples(test)
437-
test_output = map(str, [
438-
r.test_num, r.name, r.num_samples, r.min, r.max, int(r.mean),
439-
int(r.sd), r.median, r.max_rss])
440-
if log:
441-
print(line_format.format(*test_output))
442-
else:
443-
print(','.join(test_output))
444-
output.append(test_output)
441+
result = result_values(driver.run_independent_samples(test))
442+
console_log(result)
443+
results.append(result)
445444

446445
print('\nTotal performance tests executed: {0}'.format(len(driver.tests)))
447-
csv_log = '\n'.join([','.join(l) for l in output]) + '\n'
446+
csv_log = '\n'.join([','.join(r) for r in results]) + '\n'
448447
return csv_log
449448

450449

0 commit comments

Comments
 (0)