#!/usr/bin/python3 import os import sys def convert2float(val): try: return float(val) except: return val def parse_file(fname): with open(fname) as f: data = f.readlines() ret = [] for row in data: row = row.strip() if row == "": continue ret.append(list(map(convert2float, row.split()))) return ret def strip_integers(row): return list(filter(lambda x: type(x) == str, row)) def find_item(data, header, row): headers = data[0] row = strip_integers(row) pos_x = -1 for i in range(len(data)): s = strip_integers(data[i]) if s != row: continue pos_x = i break if pos_x == -1: return None pos_y = -1 for j in range(len(headers)): if headers[j] != header: continue pos_y = j break if pos_y == -1: return None return data[pos_x][pos_y] def compare_values(data_cur, data_prev): ret = [] headers = data_cur[0] for i in range(len(data_cur)): ret.append([]) row_cur = data_cur[i] for j in range(len(row_cur)): item_cur = row_cur[j] if type(item_cur) == str: item = " ".join(item_cur.split("_")).capitalize() else: item_prev = find_item(data_prev, headers[j], row_cur) if j != len(row_cur) - 1: fmt = "{:.3f}ms" scale = 1000.0 else: fmt = "{:.2f}MiB" scale = 1.0 / 1024.0 if item_prev != None: if item_prev != 0.0: diff = (item_cur - item_prev) / item_prev else: diff = 0.0 if diff < -0.05 and item_cur > 0.0005: sign = " {icon arrow-down color=green}" elif diff > 0.05 and item_cur > 0.0005: sign = " {icon arrow-up color=red}" else: sign = "" fmt += " //({:+.2%})//{}" item = fmt.format(item_cur * scale, diff, sign) else: fmt += "//(new)// {{icon plus color=blue}}" item = fmt.format(item_cur * scale) ret[i].append(item) return ret def generate_remarkup(data): ret = "==== Macro benchmark summary: ====\n\n" ret += "
{} | \n" else: fmt = "{} | \n" ret += fmt.format(item) ret += "
---|