https://github.com/wala/WALA
Raw File
Tip revision: e41ef905d4ca9c7e1671c18fb43c2322d723f831 authored by Ben Liblit on 31 March 2024, 17:56:14 UTC
Use new API for updating collection properties
Tip revision: e41ef90
summarize-time-trials
#!/usr/bin/python3

import numpy
import pandas


def main():
    # load results, then identify successful and skipped tests
    frame = pandas.read_csv('build/time-trials.csv')
    results = frame['resultType']
    successes = results == 'SUCCESS'
    skips = results == 'SKIPPED'

    # report failed tests, if any
    failures = frame[~(successes | skips)]
    if not failures.empty:
        print('failed tests:')
        print(failures)
        return

    # aggregate multiple trials of each individual test method
    frame['elapsedTime'] = frame['endTime'] - frame['startTime']
    grouped = frame[successes].groupby(['className', 'name'])['elapsedTime']

    # print very wide tables in full; assume user can scroll horizontally
    pandas.set_option('display.width', None)
    pandas.set_option('display.max_colwidth', -1)

    # summarize distribution of elapsed times, including fine-grained
    # percentiles at the upper (slowest) end
    times = grouped.mean()
    times.sort_values(inplace=True)
    print('Overall distribution and percentiles of elapsed times:\n')
    print(times.describe(percentiles=numpy.arange(.8, 1, .01)))
    print('\n')

    # print slowest individual tests, showing only those in the 95% percentile
    # or higher (slower)
    ranked_times = pandas.DataFrame(times)
    ranked_times['percentRank'] = times.rank(pct=True)
    elapsed_times = ranked_times['elapsedTime']
    ranked_times['fractionOfTotal'] = elapsed_times / elapsed_times.sum()
    is_slow = ranked_times['percentRank'] >= .95
    slowest_tests = ranked_times[is_slow][::-1]
    print('Slowest individual tests:')
    print(slowest_tests.to_string(formatters={'percentRank': '{:.1%}'.format}))


if __name__ == '__main__':
    main()
back to top