compare_benchmarks.py 1.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#!bin/python3
import sys
import os

if len(sys.argv) < 2:
    print("Please pass the name of the benchmark target as an argument!")
    exit(1)

target = sys.argv[1]
print('Comparing current modifications for benchmark target ' + target)

print('Executing current version...')
print(os.popen('cd cmake-build-release; make ' + target).read())
current = os.popen('chrt -rr 99 ./cmake-build-release/bin/' + target).read()

print('Executing old version...')
print(os.popen('git stash push').read())
print(os.popen('cd cmake-build-release; make ' + target).read())
before = os.popen('chrt -rr 99 ./cmake-build-release/bin/' + target).read()
print(os.popen('git stash pop').read())

print('=======================================================')
current = [float(value) for value in current.split(',')]
before = [float(value) for value in before.split(',')]


def formate_change(change):
    if change > 1.05:
        color = '31'
    elif change < 0.95:
        color = '32'
    else:
        color = '30'

    return '\033[1;' + color + ';40m %8.2f' % (change * 100) + '  %'


format_string = ' '.join(['%10.2f us'] * len(current))
print('old: ' + format_string % tuple(before))
print('new: ' + format_string % tuple(current))
print('=' * 55)
change = [c / b for b, c in zip(before, current)]
formated_change = ''.join(list(map(formate_change, change)))
print(formated_change)