Skip to content

Commit d552424

Browse files
committed
tools/bench-content-inspect: add python compare script
To show differences betweeen 2 result files or between spm algos in a single result file.
1 parent 4dc39ee commit d552424

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import sys
2+
import argparse
3+
import csv
4+
import itertools
5+
6+
baseline_hs = list()
7+
baseline_bm = list()
8+
baseline_mm = list()
9+
branch_hs = list()
10+
branch_bm = list()
11+
branch_mm = list()
12+
13+
def load_baseline(path):
14+
with open(path, newline='') as csvfile:
15+
f = csv.reader(csvfile, delimiter=',')
16+
h = next(itertools.islice(f, 0, 1))
17+
global baseline_header
18+
baseline_header = h
19+
20+
for row in f:
21+
if (row[0] == 'hs'):
22+
baseline_hs.append(row)
23+
elif (row[0] == 'bm'):
24+
baseline_bm.append(row)
25+
elif (row[0] == 'mm'):
26+
baseline_mm.append(row)
27+
28+
def load_branch(path):
29+
with open(path, newline='') as csvfile:
30+
f = csv.reader(csvfile, delimiter=',')
31+
_h = next(itertools.islice(f, 0, 1))
32+
33+
for row in f:
34+
if (row[0] == 'hs'):
35+
branch_hs.append(row)
36+
elif (row[0] == 'bm'):
37+
branch_bm.append(row)
38+
elif (row[0] == 'mm'):
39+
branch_mm.append(row)
40+
41+
def report_baseline_vs_branch(threshold):
42+
global baseline_header
43+
h = baseline_header
44+
cnt = len(baseline_bm)
45+
46+
print("\n%-64s: %-8s %8s \t\tPercent" % ("HS/VS", "baseline", "branch"))
47+
for idx in range(0, cnt):
48+
bl = baseline_hs[idx]
49+
br = branch_hs[idx]
50+
51+
for i in range(1, len(bl)):
52+
if len(bl[i]) == 0:
53+
continue
54+
p = int(br[i]) / int(bl[i]) * 100
55+
if p > (100 + threshold) or p < (100 - threshold):
56+
cs = "\x1b[1;31m" if (p > (100 + threshold)) else "\x1b[32m"
57+
ce = "\x1b[0m"
58+
print("%-64s: %8d %8d:\t\t%s%0.2f%s" % (h[i], int(bl[i]), int(br[i]), cs, p, ce))
59+
60+
61+
print("\n%-64s: %-8s %8s \t\tPercent" % ("BM", "baseline", "branch"))
62+
for idx in range(0, cnt):
63+
bl = baseline_bm[idx]
64+
br = branch_bm[idx]
65+
66+
for i in range(1, len(bl)):
67+
if len(bl[i]) == 0:
68+
continue
69+
p = int(br[i]) / int(bl[i]) * 100
70+
if p > (100 + threshold) or p < (100 - threshold):
71+
cs = "\x1b[1;31m" if (p > (100 + threshold)) else "\x1b[32m"
72+
ce = "\x1b[0m"
73+
print("%-64s: %8d %8d:\t\t%s%0.2f%s" % (h[i], int(bl[i]), int(br[i]), cs, p, ce))
74+
75+
print("\n%-64s: %-8s %8s \t\tPercent" % ("MM", "baseline", "branch"))
76+
for idx in range(0, cnt):
77+
bl = baseline_mm[idx]
78+
br = branch_mm[idx]
79+
80+
for i in range(1, len(bl)):
81+
if len(bl[i]) == 0:
82+
continue
83+
p = int(br[i]) / int(bl[i]) * 100
84+
if p > (100 + threshold) or p < (100 - threshold):
85+
cs = "\x1b[1;31m" if (p > (100 + threshold)) else "\x1b[32m"
86+
ce = "\x1b[0m"
87+
print("%-64s: %8d %8d:\t\t%s%0.2f%s" % (h[i], int(bl[i]), int(br[i]), cs, p, ce))
88+
89+
def report_spms(threshold):
90+
global baseline_header
91+
h = baseline_header
92+
cnt = len(baseline_bm)
93+
94+
print("\n%-64s: %-8s %8s \t\tPercent" % ("HS/VS vs BM", "BM", "HS/VS"))
95+
for idx in range(0, cnt):
96+
bl = baseline_bm[idx]
97+
br = baseline_hs[idx]
98+
99+
for i in range(1, len(bl)):
100+
if len(bl[i]) == 0:
101+
continue
102+
p = int(br[i]) / int(bl[i]) * 100
103+
if p > (100 + threshold) or p < (100 - threshold):
104+
cs = "\x1b[1;31m" if (p > (100 + threshold)) else "\x1b[32m"
105+
ce = "\x1b[0m"
106+
print("%-64s: %8d %8d:\t\t%s%0.2f%s" % (h[i], int(bl[i]), int(br[i]), cs, p, ce))
107+
108+
print("\n%-64s: %-8s %8s \t\tPercent" % ("BM vs MM", "BM", "MM"))
109+
for idx in range(0, cnt):
110+
bl = baseline_bm[idx]
111+
br = baseline_mm[idx]
112+
113+
for i in range(1, len(bl)):
114+
if len(bl[i]) == 0:
115+
continue
116+
p = int(br[i]) / int(bl[i]) * 100
117+
if p > (100 + threshold) or p < (100 - threshold):
118+
cs = "\x1b[1;31m" if (p > (100 + threshold)) else "\x1b[32m"
119+
ce = "\x1b[0m"
120+
print("%-64s: %8d %8d:\t\t%s%0.2f%s" % (h[i], int(bl[i]), int(br[i]), cs, p, ce))
121+
122+
print("\n%-64s: %-8s %8s \t\tPercent" % ("MM vs HS/VS", "MM", "HS/VS"))
123+
for idx in range(0, cnt):
124+
bl = baseline_mm[idx]
125+
br = baseline_hs[idx]
126+
127+
for i in range(1, len(bl)):
128+
if len(bl[i]) == 0:
129+
continue
130+
p = int(br[i]) / int(bl[i]) * 100
131+
if p > (100 + threshold) or p < (100 - threshold):
132+
cs = "\x1b[1;31m" if (p > (100 + threshold)) else "\x1b[32m"
133+
ce = "\x1b[0m"
134+
print("%-64s: %8d %8d:\t\t%s%0.2f%s" % (h[i], int(bl[i]), int(br[i]), cs, p, ce))
135+
136+
def main():
137+
parser = argparse.ArgumentParser(description="Verification test runner.")
138+
parser.add_argument("--baseline", action="store",
139+
help="Baseline csv file")
140+
parser.add_argument("--branch", action="store",
141+
help="Branch csv file")
142+
parser.add_argument("--threshold", action="store",
143+
help="Threshold percentage piont value for reporting a difference")
144+
args = parser.parse_args()
145+
load_baseline(args.baseline)
146+
if args.branch != None and len(args.branch) > 0:
147+
load_branch(args.branch)
148+
report_baseline_vs_branch(int(args.threshold))
149+
else:
150+
report_spms(int(args.threshold))
151+
152+
if __name__ == "__main__":
153+
sys.exit(main())

0 commit comments

Comments
 (0)