process.py 4.1 KB

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