source: tools/test_time.py @ 1a2ba84

Last change on this file since 1a2ba84 was 03b1815, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Added a Python script for reviewing the timing of the test suite.

  • Property mode set to 100755
File size: 1.7 KB
RevLine 
[03b1815]1#!/usr/bin/env python3
2"""Inspect test results for timing information.
3
4Run on a file that contains results from tests/test.py to see results.
5"""
6
7
8import argparse
9from datetime import timedelta
10import re
11import statistics
12
13
14def parse_args(args=None):
15    parser = argparse.ArgumentParser(
16        description='Summarize performance results from a test run.')
17    parser.add_argument('result_file', type=argparse.FileType('r'))
18    return parser.parse_args(args)
19
20
21def str_to_time(time_str):
22    match = re.search('([0-9]+):([0-9]+)[.]([0-9]+)', time_str)
23    if not match:
24        raise Exception('Badly formatted')
25    minutes, seconds, milli = (int(x) for x in match.groups())
26    return timedelta(minutes=minutes, seconds=seconds, milliseconds=milli)
27
28
29def line_to_entry(line):
30    match = re.search('([^\t ]+) +PASSED +C( n/a|.*) - R( n/a|.*)', line)
31    if not match:
32        return None
33    test_id, compile_str, run_str = match.groups()
34    compile_time = None if ' n/a' == compile_str else str_to_time(compile_str)
35    run_time = None if ' n/a' == run_str else str_to_time(run_str)
36    return test_id, compile_time, run_time
37
38
39def iter_file_entries(open_file):
40    with open_file as file:
41        for line in file.readlines():
42            entry = line_to_entry(line)
43            if entry is not None:
44                yield entry
45
46
47def entry_to_compile_seconds(entry):
48    _id, compile_time, _run_time = entry
49    return compile_time.total_seconds()
50
51
52if '__main__' == __name__:
53    args = parse_args()
54    mean = statistics.geometric_mean(
55        map(entry_to_compile_seconds, iter_file_entries(args.result_file)))
56    print('Source File:', args.result_file.name)
57    print('Geometric Mean:', mean)
Note: See TracBrowser for help on using the repository browser.