compare_benchmarks.py 1.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#!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 old version...')
13 14 15 16 17
git_stash_result = os.popen('git stash push').read()
if 'No local changes' in git_stash_result:
    print('No local changes, nothing to compare, exiting!')
    exit(1)
print(git_stash_result)
18
print(os.popen('cd cmake-build-release; make ' + target).read())
19
before = os.popen('nice -20 ./cmake-build-release/bin/' + target).read()
20 21
print(os.popen('git stash pop').read())

22 23 24 25
print('Executing current version...')
print(os.popen('cd cmake-build-release; make ' + target).read())
current = os.popen('nice -20 ./cmake-build-release/bin/' + target).read()

26 27 28
print('=======================================================')
current = [float(value) for value in current.split(',')]
before = [float(value) for value in before.split(',')]
29 30
current.append(sum(current))
before.append(sum(before))
31 32 33 34 35 36 37 38 39 40


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

41
    return '\033[1;' + color + ';40m %9.2f' % (change * 100) + '  %'
42 43


44 45 46
format_string = '|'.join(['%10.2f us'] * len(current))
print('old     | ' + format_string % tuple(before))
print('new     | ' + format_string % tuple(current))
47
change = [c / b for b, c in zip(before, current)]
48 49
formated_change = '|'.join(list(map(formate_change, change)))
print('change  |' + formated_change)