1import re 2import xlsxwriter 3 4START = 0 5IN_TEST = 1 6MEASURE = 2 7CYCLE_CPP = 3 8CYCLE_C = 4 9ERROR = 5 10 11line_nb = 0 12state = START 13dimensions = "?" 14 15cpp = 0 16c = 0 17 18stats = {} 19 20with open("result.txt","r") as f: 21 lines = f.readlines() 22 for l in lines: 23 if line_nb >= 3: 24 if re.match('Error',l): 25 state = ERROR 26 continue 27 if state == ERROR: 28 state = IN_TEST 29 continue 30 if state == START: 31 if re.match(r'^[a-zA-Z]+.*$',l): 32 #print(l) 33 test_name = l.strip("\n") 34 state = IN_TEST 35 stats[test_name]=[] 36 continue 37 if state == IN_TEST: 38 if re.match(r'----',l): 39 state = MEASURE 40 continue 41 if re.match(r'^[a-zA-Z]+.*$',l): 42 state = IN_TEST 43 test_name = l.strip("\n") 44 stats[test_name]=[] 45 continue 46 if state == MEASURE: 47 dimensions = l.strip("\n") 48 state = CYCLE_CPP 49 continue 50 if state == CYCLE_CPP: 51 m = re.match(r'Cycle count = ([0-9]+)',l) 52 if m: 53 cpp = m.group(1) 54 state = CYCLE_C 55 continue 56 if state == CYCLE_C: 57 if re.match(r'----',l): 58 state = MEASURE 59 stats[test_name].append({"dim":dimensions,"cpp":cpp}) 60 continue 61 m = re.match(r'Cycle count = ([0-9]+)',l) 62 if m: 63 c = m.group(1) 64 state = IN_TEST 65 stats[test_name].append({"dim":dimensions,"cpp":cpp,"c":c}) 66 continue 67 else: 68 stats[test_name].append({"dim":dimensions,"cpp":cpp}) 69 state = IN_TEST 70 continue 71 72 73 74 75 76 line_nb = line_nb + 1 77 78dst="C:/Users/CHRFAV01/OneDrive - ARM/Documents/Presentations/CMSIS_Compute" 79 80def pos(row,col): 81 return(f"{chr(ord('A')+col)}{row}") 82 83for s in stats: 84 ns = re.sub(r'[ ]',"_",s) + ".xlsx" 85 print(ns) 86 workbook = xlsxwriter.Workbook(dst+"/"+ns) 87 worksheet = workbook.add_worksheet("Results") 88 line_nb = 0 89 90 title = workbook.add_format({'bold': True,'font_size':24}) 91 sub_title = workbook.add_format({'bold': True, 92 'font_size':14, 93 'align':"center", 94 'bg_color':"#CCCCCC"}) 95 percent = workbook.add_format({'num_format': '0.00%'}) 96 dimEven = workbook.add_format({'bold': True,'bg_color':"#CCCCCC"}) 97 dimOdd = workbook.add_format({'bold': True,'bg_color':"#EEEEEE"}) 98 99 worksheet.write(line_nb,0, s,title) 100 line_nb = line_nb + 1 101 102 worksheet.set_row(line_nb, 30) 103 worksheet.set_column("D:D", 30) 104 105 if len(stats[s])==2: 106 worksheet.write(line_nb,0, 'dims',sub_title) 107 worksheet.write(line_nb,1, 'cpp',sub_title) 108 worksheet.write(line_nb, 2, 'CPP Improvement',sub_title) 109 110 else: 111 worksheet.write(line_nb,0, 'dims',sub_title) 112 worksheet.write(line_nb,1, 'cpp',sub_title) 113 worksheet.write(line_nb,2, 'c',sub_title) 114 worksheet.write(line_nb, 3, 'CPP Improvement',sub_title) 115 116 line_nb = line_nb + 1 117 for x in stats[s]: 118 if (line_nb % 2 == 0): 119 dim = dimOdd 120 else: 121 dim = dimEven 122 if "c" in x: 123 worksheet.write(line_nb,0, x["dim"],dim) 124 worksheet.write(line_nb,1, float(x["cpp"])) 125 worksheet.write(line_nb,2, float(x["c"])) 126 worksheet.write(line_nb, 3, f"=(C{line_nb+1}-B{line_nb+1})/C{line_nb+1}",percent) 127 else: 128 worksheet.write(line_nb,0, x["dim"],dim) 129 worksheet.write(line_nb,1, float(x["cpp"])) 130 worksheet.write(line_nb, 2, f"=(C{line_nb+1}-B{line_nb+1})/C{line_nb+1}",percent) 131 132 line_nb = line_nb + 1 133 134 135 136 workbook.close() 137