""" Compares the execution time of the functions in a file with the thresholds given in another file. Optionnaly compares the execution times with previous executions Prints 3 types of messages: - FAIL: A function failed to respect the threshold set - WARN: - No threshold was set for a function - No perfect match for a function-parent pair was found and no default threshold (function but no parent) was set - A function slowed down since last time it was executed - INFO: - Using a default threshold for a function - No previous execution found for a function-parent pair """ import os import sys class MalformedInputError(RuntimeError): pass class FuncData: def __init__(self, name: str = "", parent: str = "", info: str = "", time: float = .0): self.name = name # Function's name self.parent = parent # Function parent's name self.info = info # Optionnal supplementary data (currently unused) self.time = time # Function's execution time def __str__(self) -> str: my_str = "" if len(parent) != 0: my_str += f'{parent}/' my_str += f'self.name ' if len(self.info) > 0: my_str += f'({self.info.replace(" ", "_")}) ' my_str += f'| {self.time}' return my_str def from_string(string: str) -> 'FuncData': func_data = FuncData() symbol_idx = 0 # Separate symbols of string data = string.strip().split(" ") try: # Retrieve function's name and parent (if given) func = data[symbol_idx].split("/") if len(func) > 1: func_data.name = func[1] func_data.parent = func[0] else: func_data.name = func[0] symbol_idx += 1 # Retrieve infos if "(" in data[symbol_idx]: func_data.info = data[symbol_idx].strip("()") symbol_idx += 1 # Check that | separator is used before data if data[symbol_idx] == "|": symbol_idx += 1 else: raise MalformedInputError("Required '|' separator is missing") # Retrieve data func_data.time = float(data[symbol_idx]) except IndexError: raise MalformedInputError("Some required data is missing") except ValueError: raise MalformedInputError("Given data value cannot be converted to float") except OverflowError: raise MalformedInputError("Given data value is too big") return func_data """ Input files are expected to have the following format: 1 header line with no defined format N lines with function data following the "[parent/] [(info)] |